• 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有问题的可以在群里面提问。
  • 相关阅读:
    批量导入
    循环语句
    判断循环常见
    常见C运算符
    oc将字符串中单词按照出现次数(次数都不一样)降序排序,排序之后单词只出现一次,源字符串中单词用下划线连接,生成字符串也用下滑线连接
    把字符串中的字母大小写反转OC
    查找子串出现次数OC
    现有一个数组NSMutableArray, 数组有若干个NSString的元素,进行选择法排序
    终端的一些命令
    编程语言名字来历
  • 原文地址:https://www.cnblogs.com/shiyh/p/15727488.html
Copyright © 2020-2023  润新知