gpt4 book ai didi

c# - 来自数组或列表的 MS 图表 C# 数据源

转载 作者:行者123 更新时间:2023-11-30 16:33:41 25 4
gpt4 key购买 nike

我想用二维数组中的值填充图表数据,一列显示 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;
}
}
}

最佳答案

在您的 XY 类中,而不是私有(private)字段:

  private double X;
private double Y;

使用公共(public)属性:

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

DataBinding 不适用于字段。

关于c# - 来自数组或列表的 MS 图表 C# 数据源,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2940120/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com