Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/323.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 在点集合类中调用plot方法_C#_Charts_Plot_Delegates_Invoke - Fatal编程技术网

C# 在点集合类中调用plot方法

C# 在点集合类中调用plot方法,c#,charts,plot,delegates,invoke,C#,Charts,Plot,Delegates,Invoke,我尝试使用窗口窗体绘制数据,通过调用委托,我通过使用按钮触发/启动事件成功绘制了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;

我尝试使用窗口窗体绘制数据,通过调用委托,我通过使用按钮触发/启动事件成功绘制了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 });
        } 
    }
}
使用System.Windows.Forms;
使用System.Windows.Forms.DataVisualization.Charting;
命名空间绘图某些数据
{
公共部分类Form1:Form
{
公共表格1()
{
初始化组件();
}
//委派
专用委托int PLOTXYDELEASE(双x,双y);
//参数图表,图表系列,图表的x、y值
专用void PlotXYAppend(图表、系列数据系列、双x、双y)
{
//通过在点集合对象中传递addpoints方法来调用委托
调用(新plotxydegate(dataSeries.Points.AddXY),新对象[]{x,y});
} 
双[]X={1,2,3,4,5,6};
双[]Y={1,2,3,4,5,6};
私有无效按钮2\u单击(对象发送者,事件参数e)
{
对于(int i=0;i

错误:“AddY”没有重载与委托“PlotSomeData.Form1.PlotYDelegate”匹配
很抱歉,要使程序正常工作,您需要添加按钮,并从工具箱中获取图表。

调用行上的错误详细信息是什么?没有“AddY”重载匹配委托“PlotSomeData.Form1.PlotYDelegate.Um,AddY有两个重载,但您的委托两个都不匹配。为什么有双x参数???