您当前的位置: 首页 > 

君子居易

暂无认证

  • 3浏览

    0关注

    210博文

    0收益

  • 0浏览

    0点赞

    0打赏

    0留言

私信
关注
热门博文

DynamicDataDisplay波形显时间自定义格式

君子居易 发布时间:2021-10-14 11:21:49 ,浏览量:3

原创:DynamicDataDisplay 原版本在日期显示的格式上与我们的习惯不一样,特做如下修改:

自定义日期格式修改:

//MainWindow.cs中
            var ds = new EnumerableDataSource(voltagePointCollection);
            ds.SetXMapping(x => dateAxis.ConvertToDouble(x.Date));
            ds.SetYMapping(y => y.Voltage);
            plotter.AddLineGraph(ds, Colors.Green, 2, "Temperature"); // to use this method you need "using Microsoft.Research.DynamicDataDisplay;"
            MaxVoltage = 40;
            MinVoltage = 0;
            plotter.AxisGrid.BorderBrush = new SolidColorBrush(Color.FromRgb(50,50,0));
            dateAxis.LabelProvider.LabelStringFormat = "HH:mm:ss";
            
            cursorCoordinateGraph.XTextMapping = x =>
            {
                if (Double.IsNaN(x))
                    return "";

                DateTime time = dateAxis.ConvertFromDouble(x);
                return time.ToString("HH:mm:ss");
            };

LabelProviderBase.cs:

        protected virtual string GetString(LabelTickInfo tickInfo)
        {
            string text = null;
            if (CustomFormatter != null)
            {
                text = CustomFormatter(tickInfo);
            }
            if (text == null)
            {
                text = GetStringCore(tickInfo);

                if (text == null)
                    throw new ArgumentNullException(Properties.Resources.TextOfTickShouldNotBeNull);
            }
            if (LabelStringFormat != null && LabelStringFormat.Length > 0)
            {
                //text = String.Format(LabelStringFormat, text);
                if (tickInfo.Tick is System.DateTime)
                {
                    text = Convert.ToDateTime(tickInfo.Tick).ToString(LabelStringFormat);
                }
                else
                {
                    text = String.Format(LabelStringFormat, tickInfo.Tick);
                }
            }

            return text;
        }

修改底下的标签:

关注
打赏
1660814979
查看更多评论
立即登录/注册

微信扫码登录

0.0489s