2010-05-30 3 views
3

2 차원 배열에있는 값에서 차트의 데이터를 채우고 싶습니다. 하나의 열은 X 축을 나타내고 두 번째 열은 Y 축을 나타냅니다. ,하지만 그 배열에서 읽기, 그 날 내게 응용 프로그램을 실행할 때 기본 줄을 준다, 나는 목록을 사용하여 솔루션을 찾았 <>, 나는 어떤 오류가 있었는지, 그래서 내가 도와 줄 수 있다면, 나는 감사 할 것입니다 : DMS Charts 배열 또는 목록의 C# DataSource

이 대신 전용 필드로, 당신의 XY 클래스에서 코드

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; 
     } 
    } 
} 
+0

어떤 오류가 발생합니까? – SLaks

+0

이 오류는 Chart1.dataBinding(); ___ ___ 시리즈 데이터 요소는 ICS381Project.XY 유형의 값을 지원하지 않습니다.이 유형의 값만 사용할 수 있습니다. Double, Decimal, Single, int, long, uint, ulong, String, DateTime, short, ushort. –

답변

3

입니다 :

private double X; 
    private double Y; 

사용하는 공용 속성 :

public double X { get; private set; } 
public double Y { get; private set; } 

데이터 바인딩이 필드에서 작동하지 않습니다.

+0

그래, 그 문제를 해결 플러스 속성 이름에 몇 가지 오류가 : D 감사합니다 : D –

+0

헨크, 좋은 답변. 이 문제에 대한 해답을 가진 Internets의 유일한 곳입니다. 많은 감사. –