我想从二维数组中的值填充图表数据,一列将显示X轴,第二列将显示Y轴。我做到了,但没有从数组中读取,它给出了我在运行应用程序时使用了默认行,我发现了使用List 的解决方案,我遇到了一个错误,所以如果有人可以帮助我,我将非常感激:D这是代码using System;using System.Collections.Generic;using System.ComponentModel;using System.Data;using System.Drawing;using System.Linq;using System.Text;using System.Windows.Forms;namespace ICS381Project{ public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void Form1_Load(object sender, EventArgs e) { int[,] AndFunction = { { 0, 0, 0 }, { 0, 1, 0 }, { 1, 0, 0 }, { 1, 1, 1 } }; // intialized the function int[,] D_n = new int[4, 1]; // creating the D(n) int[,] x_n = new int[4, 3]; // creating X(n) vectors X1 --> x4 int[,] W_n = { { 0, 0, 0 } }; // creating and intiallizing W(n) vectors W1 --> w4 int[,] W_n_1 = { { 0, 0, 0 } }; int[,] Delta_W_n = { { 0, 0, 0 } }; int wx = 0; // int Y_n = 0; // int d_y = 0; // for (int i = 0; i < 4; i++) { D_n[i, 0] = AndFunction[i, 2]; } for (int i = 0; i < 4; i++) { for (int j = 0; j < 3; j++) { if (j == 2) x_n[i, j] = 1; else x_n[i, j] = AndFunction[i, j]; } } int step = 0; int CheckIfNoLearning = 0; int RowsPointer = 0; while (CheckIfNoLearning < 4) { //Console.Write("step= " + step+1 + "\n"); wx = (x_n[RowsPointer, 0] * W_n[0, 0]) + (x_n[RowsPointer, 1] * W_n[0, 1]) + (x_n[RowsPointer, 2] * W_n[0, 2]); //Console.Write("[ " + x_n[RowsPointer, 0] + ", " + x_n[RowsPointer, 1] + ", " + x_n[RowsPointer, 2] + "] \t"); //Console.Write("[ " + W_n[0, 0] + ", " + W_n[0, 1] + ", " + W_n[0, 2] + "] \t"); //Console.Write("" + wx + "\t"); if (wx < 0) Y_n = 0; else Y_n = 1; // Console.Write("" + Y_n + "\t"); d_y = D_n[RowsPointer, 0] - Y_n; // Console.Write("" + d_y + "\t"); Delta_W_n[0, 0] = d_y * x_n[RowsPointer, 0]; Delta_W_n[0, 1] = d_y * x_n[RowsPointer, 1]; Delta_W_n[0, 2] = d_y * x_n[RowsPointer, 2]; // Console.Write("[ " + Delta_W_n[0, 0] + ", " + Delta_W_n[0, 1] + ", " + Delta_W_n[0, 2] + "] \t"); for (int i = 0; i < 3; i++) { W_n_1[0, i] = W_n[0, i] + Delta_W_n[0, i]; } //Console.Write("[ " + W_n_1[0, 0] + ", " + W_n_1[0, 1] + ", " + W_n_1[0, 2] + "] \n"); if (W_n_1[0, 0] == W_n[0, 0] && W_n_1[0, 1] == W_n[0, 1] && W_n_1[0, 2] == W_n[0, 2] && CheckIfNoLearning == RowsPointer) CheckIfNoLearning++; else CheckIfNoLearning = 0; W_n[0, 0] = W_n_1[0, 0]; W_n[0, 1] = W_n_1[0, 1]; W_n[0, 2] = W_n_1[0, 2]; //Console.Write("W_n= [ " + W_n[0, 0] + ", " + W_n[0, 1] + ", " + W_n[0, 2] + "] \n"); RowsPointer = (RowsPointer + 1) % 4; step++; } double[,] equation = {{-10,0},{-9,0},{-8,0}, {-7,0},{-6,0},{-5,0}, {-4,0},{-3,0},{-2,0}, {-1,0},{0,0},{1,0}, {2,0},{3,0},{4,0}, {5,0},{6,0},{7,0}, {8,0},{9,0},{10,0}}; List<XY> xy = new List<XY>(); for (int i = 0; i < 21; i++) { equation[i, 1] = (-1 * (W_n_1[0, 1] * equation[i, 0] + W_n_1[0, 2])) / W_n_1[0, 0]; xy.Add(new XY(equation[i,0], equation[i,1])); } chart1.DataSource = xy; chart1.Series[0].XValueMember = "Y"; chart1.Series[0].YValueMembers = "X"; chart1.ChartAreas["ChartArea1"].AxisX.Interval = 1; chart1.DataBind(); } } public class XY { private double X; private double Y; public double DayOfWeek { get { return X; } set { X = value; } } public double Sales { get { return Y; } set { Y = value; } } public XY(double X, double Y) { this.X = X; this.Y = Y; } }} (adsbygoogle = window.adsbygoogle || []).push({}); 最佳答案 在您的XY类中,而不是私有字段中: private double X; private double Y;使用公共属性: public double X { get; private set; } public double Y { get; private set; }DataBinding在字段上不起作用。 (adsbygoogle = window.adsbygoogle || []).push({});
10-04 21:04