2010-05-30 12 views
3

Je veux remplir les données des graphiques à partir des valeurs que j'ai en tableau 2D, une colonne présentera l'axe X et la seconde est présente l'axe Y. Je l'ai fait , mais ce n'est pas la lecture du tableau, il me donne la ligne par défaut lorsque je lance l'application, j'ai trouvé une solution en utilisant la liste <>, j'ai eu une erreur, donc si quelqu'un pouvait m'aider, je serais reconnaissant: DMS Charts C# DataSource de tableau ou de liste

c'est le code

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

Quelle erreur obtenez-vous? – SLaks

+0

je reçois cette erreur sur le Chart1.dataBinding(); ___ ___ Les points de données de série ne prennent pas en charge les valeurs de type ICS381Project.XY seules les valeurs de ces types peuvent être utilisées: Double, Decimal, Single, int, long, uint, ulong, String, DateTime, short, ushort. –

Répondre

3

Dans votre classe XY, au lieu des champs privés:

private double X; 
    private double Y; 

utilisation des propriétés publiques:

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

DataBinding ne fonctionne pas sur les champs.

+0

ouais qui a résolu le problème plus j'ai eu une erreur dans les noms de propriétés: D merci: D –

+0

Henk, Grande réponse. C'est le seul endroit sur les Internets avec une réponse au problème. Merci beaucoup. –