码迷,mamicode.com
首页 > Windows程序 > 详细

C# DEV--CharControl

时间:2015-05-13 16:24:57      阅读:475      评论:0      收藏:0      [点我收藏+]

标签:

使用DEV的图标控件CharControl,代码如下:

            try
            {
                //声明折线
                XYDiagram Diagram = chartControl1.Diagram as XYDiagram;
                Diagram.AxisX.GridSpacingAuto = false;
                Diagram.AxisX.DateTimeScaleOptions.MeasureUnit = DateTimeMeasureUnit.Minute;//这个可以根据你自己的情况设置
                Diagram.AxisX.DateTimeScaleOptions.GridAlignment = DateTimeGridAlignment.Minute; //这个是间隔单位
                //Diagram.AxisX.GridSpacing = 60; // 每60秒为一个间隔。
                Diagram.AxisX.Label.DateTimeOptions.Format = DateTimeFormat.Custom;
                Diagram.AxisX.Label.DateTimeOptions.FormatString = "MM-dd HH:mm";
                Diagram.AxisX.Range.Auto = false; //要开启滚动条必须将其设置为false

                //X轴开始时间
                DateTime XbeginTime = new DateTime();
                //X轴结束时间
                DateTime XendTime = new DateTime();

                if (this.lueDeviceSN.EditValue.ToString() == "%")
                {
                }
                else
                {
                    DataTable dt = InfoService.GetRealTimeView(StaticInfo.enterpriseID
                        , this.lueDeviceSN.EditValue.ToString());
                    if (dt != null)
                    {
                        if (dt.Rows.Count > 0)
                        {
                            XendTime = ConvertHelper.TryToDatetime(dt.Rows[0]["UpdateTime"].ToString().Replace("", ":"));
                            XbeginTime = ConvertHelper.TryToDatetime(dt.Rows[dt.Rows.Count - 1]["UpdateTime"].ToString().Replace("", ":"));
                            this.chartControl1.Series[0].ArgumentScaleType = ScaleType.DateTime;
                            this.chartControl1.Series[0].ArgumentDataMember = "UpdateTime";
                            this.chartControl1.Series[0].ValueDataMembers[0] = "Temperature";

                            this.chartControl1.Series[0].Name = this.lueDeviceSN.EditValue.ToString();
                            this.chartControl1.Series[0].Points.BeginUpdate();
                            this.chartControl1.Series[0].Points.Clear();
                            for (int j = 0; j < dt.Rows.Count; j++)
                            {
                                this.chartControl1.Series[0].Points.Add(
                                    new SeriesPoint(ConvertHelper.TryToDatetime(dt.Rows[j]["UpdateTime"].ToString().Replace("", ":"))
                                        , ConvertHelper.TryToDouble(dt.Rows[j]["Temperature"])));
                            }
                            this.chartControl1.Series[0].Points.EndUpdate();
                        }
                    }
                }
                if (XbeginTime == XendTime)
                {
                    XbeginTime = DateTime.Now;
                    XendTime = XbeginTime.AddMinutes(20);
                }
                Diagram.AxisX.Range.MaxValue = XendTime;
                Diagram.AxisX.Range.MinValue = XbeginTime;
                Diagram.AxisX.Title.Text = "时间";
                Diagram.AxisY.Range.MinValue = -5;
                Diagram.AxisY.Range.MaxValue = 40;
                Diagram.AxisY.Title.Text = "温度值";
            }
            catch (Exception ex)
            {
            }

 由于时间是通过JSON传输解析的,发生了中文:的问题。

C# DEV--CharControl

标签:

原文地址:http://www.cnblogs.com/bmbh/p/4500603.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!