我尝试使用窗口形式绘制DATA,通过调用委托,我使用按钮触发/启动事件成功绘制了XY图形(参见下面的代码)。
我不明白为什么我的代码适用于绘制XY点,但当我只想绘制Y点时它不起作用。
我的意思是单独绘制Y即X = 0,1,2,3,4,递增1或通常任何固定增量,可以是0.1或0.01,或任何东西。但Y由用户传入。
using System.Windows.Forms;
using System.Windows.Forms.DataVisualization.Charting;
namespace PlottingSomeData
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
// Delegate
private delegate int PlotXYDelegate(double x, double y);
// parameter Chart, Series of the chart, x,y values of the graph
private void PlotXYAppend(Chart chart, Series dataSeries, double x, double y)
{
// invoke the delegate by passing in the add points method in point collection object
chart.Invoke(new PlotXYDelegate(dataSeries.Points.AddXY), new Object[] { x, y });
}
double[] X = { 1, 2, 3, 4, 5, 6 };
double[] Y = { 1, 2, 3, 4, 5, 6 };
private void button2_Click(object sender, EventArgs e)
{
for (int i = 0; i < X.Length || i < Y.Length; i++)
{
PlotXYAppend(this.chart2, this.chart2.Series[0], X[i], Y[i]);
}
}
//UP to this line... the code below doesn't work.
private delegate int PlotYDelegate(double x, double y);
private void PlotYAppend(Chart chart, Series dataSeries, double y)
{
// I do the same here but it fails... for adding single Y value.
// There is error for the invoking line. I don't really know what the problem is.
chart.Invoke(new PlotYDelegate(dataSeries.Points.AddY), new Object[] { y });
}
}
}
错误:&#39; AddY&#39;匹配委托&#39; PlotSomeData.Form1.PlotYDelegate 很抱歉要让程序运行,您需要添加按钮并从工具箱中获取图表。