C# 如何将数据放入图形中

C# 如何将数据放入图形中,c#,winforms,visual-studio-2010,list,zedgraph,C#,Winforms,Visual Studio 2010,List,Zedgraph,我用的是ZedGraph的图表。我想在里面放一些数据,但我不知道怎么放。 我的数据由计时器每1分钟来一次,它们是整数。Zedgraph的问题是它必须是双重的。但这不是问题所在。我希望图形每1分钟生成一次,每1分钟,条形图中将添加一个新条。我的图表有6个系列。A-F DateTime dtime = DateTime.Now; int a = ctrscan.analyzeNewScanQuality1A(); int b = ctrscan.an

我用的是ZedGraph的图表。我想在里面放一些数据,但我不知道怎么放。 我的数据由计时器每1分钟来一次,它们是整数。Zedgraph的问题是它必须是双重的。但这不是问题所在。我希望图形每1分钟生成一次,每1分钟,条形图中将添加一个新条。我的图表有6个系列。A-F

        DateTime dtime = DateTime.Now;

        int a = ctrscan.analyzeNewScanQuality1A();
        int b = ctrscan.analyzeNewScanQuality1B();
        int c = ctrscan.analyzeNewScanQuality1C();
        int D = ctrscan.analyzeNewScanQuality1D();
        int e = ctrscan.analyzeNewScanQuality1E();
        int f = ctrscan.analyzeNewScanQuality1F();


        double time = Convert.ToDouble(dtime.Minute);

        double[] y = { 90, 100, 95, 35, 80, 35 };
        double[] y2 = { 90, 100, 95, 35, 80, 35 };
        double[] y3 = { 80, 110, 65, 15, 54, 67 };
        double[] y4 = { 120, 125, 100, 40, 105, 75 };
        double[] y5 = { 20, 125, 100, 40, 105, 75 };
        double[] y6 = { 220, 125, 100, 40, 105, 75 };

        double[] x = {time}; 

        BarItem myBar = myPane.AddBar("Quality A", x, y, Color.Red);
此图表仅接受双精度列表中的数字。正如你所看到的,每个“y”代表我的一个A-F。列表中的数字只是随机数,不可使用

如你所见,我得到的是整数。我知道如何转换,所以这不是问题。我的问题是:如何将其放入图表中? 我想把它放在图中,1分钟后,一组全新的整数将到达。然后我想要旧的集合,在图中有新的集合。 最后一行是让你看看我是如何控制我的系列的

我正在使用visual studio c#,并在winform中编写

希望你能理解

公共部分类图表:表单
       public partial class Chart : Form
{
    public Chart()
    {
        InitializeComponent();
    }


    private void SetSize()
    {
        zedGraphControl1.Location = new Point(10, 10);
        // Leave a small margin around the outside of the control

        zedGraphControl1.Size = new Size(ClientRectangle.Width - 20,
                                ClientRectangle.Height - 20);
    }

    private void Chart_Load(object sender, EventArgs e)
    {
        CreateGraph(zedGraphControl1);
        SetSize();
    }

    private void CreateGraph(ZedGraphControl zg1)
    {
        GraphPane myPane = zedGraphControl1.GraphPane;
        myPane.XAxis.Type = AxisType.Date;

        PointPairList PPLa = new PointPairList();
        PointPairList PPLb = new PointPairList();
        PointPairList PPLc = new PointPairList();
        PointPairList PPLd = new PointPairList();
        PointPairList PPLe = new PointPairList();
        PointPairList PPLf = new PointPairList();

        int Max = 1;

        for (int i = 0; i < Max; i++)
        {
            DateTime dtime = DateTime.Now;

            //int a = ctrscan.analyzeNewScanQuality1A();
            //int b = ctrscan.analyzeNewScanQuality1B();
            //int c = ctrscan.analyzeNewScanQuality1C();
            //int d = ctrscan.analyzeNewScanQuality1D();
            //int e = ctrscan.analyzeNewScanQuality1E();
            //int f = ctrscan.analyzeNewScanQuality1F();

            int a = 1;
            int b = 1;
            int c = 2;
            int d = 1;
            int e = 3;
            int f = 2;

            double date = (double)new XDate(dtime);

            PPLa.Add(date, (double)a);
            PPLb.Add(date, (double)b);
            PPLc.Add(date, (double)c);
            PPLd.Add(date, (double)d);
            PPLe.Add(date, (double)e);
            PPLf.Add(date, (double)f);

            BarItem myBara = myPane.AddBar("Bar A", PPLa, Color.Red);
            BarItem myBarb = myPane.AddBar("Bar B", PPLb, Color.Blue);
            BarItem myBarc = myPane.AddBar("Bar C", PPLc, Color.Green);
            BarItem myBard = myPane.AddBar("Bar D", PPLd, Color.Black);
            BarItem myBare = myPane.AddBar("Bar E", PPLe, Color.Yellow);
            BarItem myBarf = myPane.AddBar("Bar F", PPLf, Color.Orange);


            zedGraphControl1.AxisChange();

           // sleep(1 minute);

        }
        zg1.AxisChange();
    }

    private void Chart_Resize(object sender, EventArgs e)
    {
        SetSize();
    }
}
{ 公共图表() { 初始化组件(); } 私有void SetSize() { zedGraphControl1.位置=新点(10,10); //在控件外部留一小段空白 zedGraphControl1.Size=新尺寸(ClientRectangle.Width-20, ClientRectangle.高度-20); } 私有无效图表加载(对象发送方、事件参数e) { CreateGraph(zedGraphControl1); 设置大小(); } 私有void CreateGraph(ZedGraphControl zg1) { GraphPane myPane=zedGraphControl1.GraphPane; myPane.XAxis.Type=AxisType.Date; PointPairList PPLa=新的PointPairList(); PointPairList PPLb=新的PointPairList(); PointPairList PPLc=新的PointPairList(); PointPairList PPLd=新的PointPairList(); PointPairList PLE=新的PointPairList(); PointPairList PPLf=新的PointPairList(); int Max=1; 对于(int i=0;i
每分钟刷新一次图形,您需要使用新添加的值重新绘制它。你需要自己弄清楚睡眠时间(1分钟)


加载Form1时调用Chart_load

可能没有添加足够的额外内容:您的表单中添加了zedgraphControl,design?我用我所有的东西为你做了编辑(即使是一个显示图形的小示例,您希望我在一个新类中创建它吗?)我在:myPane.XAxis.Type=AxisType.Date处遇到一个错误;它希望我编写myPane.XAxis.Type=ZedGrpah.AxisType.Date;nr 1:在这个示例中不需要创建新类。您可以首先使用一个空白表单,将zedgraphcontrol添加到您的设计中n、 加载表单时执行操作,在表单类中复制此代码(可能将图表重命名为form1)是的,这是图表的名称。当你将工具箱中的zedgraph添加到表单中时,大多数情况下它被命名为zedgraphcontrol1。现在它可以工作了。非常感谢你对一个新手的耐心,但我正在努力学习,我很高兴有像你这样的人,他们花时间和精力帮助像我这样的人。非常感谢。现在我正在尝试我一个人,但如果我以后遇到问题,我能在这里联系你吗?