zoukankan      html  css  js  c++  java
  • ZedGraph制作动态更新的曲线图(用定时器)

    public Form1()
      {

                ////初始化
                myPane = nodeChart.GraphPane;
                 myPane.Title.Text = "节点-时间趋势图\n(Time-Values)";
                myPane.XAxis.Title.Text = "节点时间";
                myPane.YAxis.Title.Text = "节点值";

        //X轴时间格式

            myPane.XAxis.Type = AxisType.Date;
                myPane.XAxis.Scale.Format = "HH:mm:ss";


                //myPane.XAxis.Scale.Min = 0;
                //////X轴最大30
                //myPane.XAxis.Scale.Max = 30;
                //////X轴小步长1,也就是小间隔
                //myPane.XAxis.Scale.MinorStep = 1;
                //////X轴大步长为5,也就是显示文字的大间隔
                ////myPane.XAxis.Scale.MajorStep = 5;


                //nodeChart.AxisChange();
                //nodeChart.GetChildAtPoint().
                timer1.Interval = 100;
                timer1.Enabled = true;
                timer1.Start();
                myCurve = myPane.AddCurve("curve 1", Plist, Color.Blue, SymbolType.Diamond);
                myCurve2 = myPane.AddCurve("curve 2", Plist1, Color.Red, SymbolType.Circle);
                // 设置图标的颜色和渐变色
                myPane.Chart.Fill = new Fill(Color.White,
                Color.FromArgb(255, 255, 166), 45.0F);
                //BarItem.CreateBarLabels(myPane, false, "f0");
            }

     private void timer1_Tick(object sender, EventArgs e)
            {
                timer1.Stop();
                if (timeBo)
                {

                    RollingPointPairList list = new RollingPointPairList(1200);
                    RollingPointPairList list1 = new RollingPointPairList(1200);

                    //如果重新选择了节点号,就清空之前的趋势图曲线,并重新赋值给变量
                    if (comboBoxNodeID != comboBoxItemNodeID.Text.ToString())
                    {
                        myCurve.Clear();
                        myCurve2.Clear();
                        Plist.Clear();
                        Plist1.Clear();
                        comboBoxNodeID = comboBoxItemNodeID.Text.ToString();
                        nodeChart.Refresh();
                    }

                    List<object> objList = ListChartData();
                    //X轴时间变量

                     for (int i = 0; i < objList.Count; i++)
                    {
                        //double time = (double)new XDate(DateTime.Now.AddSeconds(-(100 - i)));
                        double time = (double)new XDate(DateTime.Now);
                        List<string> listStr = (List<string>)objList[i];
                        if (listStr[0] == comboBoxItemNodeID.Text)
                        {
                            if (listStr.Count > 2)
                            {
                                double value = Convert.ToDouble(listStr[1]);
                                double value1 = Convert.ToDouble(listStr[2]);
                                Plist.Add(time, value);
                                Plist1.Add(time, value1);
                            }
                            else
                            {
                                double value = Convert.ToDouble(listStr[1]);
                                Plist.Add(time, value);
                                //MessageBox.Show("a");
                            }

              //刷新
                            nodeChart.Refresh();
                        }
                    }
                    ////立方形
                    //BarItem myCurve = myPane.AddBar("curve 1", Plist, Color.Blue);
                    //BarItem myCurve2 = myPane.AddBar("curve 2", Plist1, Color.Red);

                    //LineItem myCurve = myPane.AddCurve("curve 1", list, Color.Blue);
                    //LineItem myCurve2 = myPane.AddCurve("curve 2", list1, Color.Red);
                    nodeChart.AxisChange();
                    //nodeChart.Refresh();


                    //nodeChart.Invalidate();

                    // 创建每条bar的label,其中第2个参数表示是否显示在bar的中心位置,第3个参数表示label的排列方向
                    //BarItem.CreateBarLabels(myPane, false, "f0");

                    if (myCurve.NPts>40)
                    {
                            myCurve.RemovePoint(0);
                    }
                    if (myCurve2.NPts > 40)
                    {                 
                            myCurve2.RemovePoint(0);
                    }
                    timer1.Start();
                }
            }

    JAVA&NET技术QQ群号:456257217有问题的可以在群里面提问。
  • 相关阅读:
    hdu 4747 Mex( 线段树? 不,区间处理就行(dp?))
    hdu 5692 Snacks(dfs时间戳+线段树)
    hdu 1864 最大报销额(背包)
    hdu 2955 Robberies(概率背包)
    hdu 4055 Number String (基础dp)
    4516: [Sdoi2016]生成魔咒
    2555: SubString
    后缀自动机·小记
    CF 1114 E. Arithmetic Progression
    CF 1114 D. Flood Fill
  • 原文地址:https://www.cnblogs.com/shiyh/p/15727488.html
Copyright © 2011-2022 走看看