简体   繁体   English

时间:2019-05-16 标签:c#windowsapplicationLiveChartsxaxisdateforma

[英]c# windows application Live Charts x axis date forma

Hello everyone i working in project that convert data (date and value) to graphic curve .大家好,我在将数据(日期和值)转换为图形曲线的项目中工作。 i have problem with x axis the value of date printing in double format , i want this values showing like this format 14:12:35我有 x 轴的问题,双格式日期打印的值,我希望这个值显示为这种格式 14:12:35

var gradientBrush = new LinearGradientBrush
                 {
                     StartPoint = new System.Windows.Point(0, 0),
                     EndPoint = new System.Windows.Point(0, 1)
                 };
                 gradientBrush.GradientStops.Add(new GradientStop(System.Windows.Media.Color.FromRgb(33, 148, 241), 0.2));
                 gradientBrush.GradientStops.Add(new GradientStop(Colors.Transparent, 1));


                 cartesianChart1.Series.Add(new LineSeries
                 {
                     Values = GetData(),
                     Fill = gradientBrush,
                     StrokeThickness = 0.9,
                     PointGeometry = null
                 });



        cartesianChart1.Zoom = ZoomingOptions.X; 




private ChartValues<DateTimePoint> GetData()
        {

            var values = new ChartValues<DateTimePoint>();

            for (var i = 0; i <lsTemp.Count(); i++)
            {

             // System.DateTime.Today.AddDays(i)
                values.Add(new DateTimePoint(lsDataTime[i], lsTemp[i]));
            }

            return values;
        }

enter image description here在此处输入图片说明

you need to set LabelFormatter property of Axis class.您需要设置 Axis 类的 LabelFormatter 属性。 Something like this:像这样的东西:

 AxisX = new Axis
            {
                Title = "Date",
                Separator = new Separator { IsEnabled = false,Step = 1 },
                LabelsRotation = -90,
                Foreground = new SolidColorBrush(Colors.Black),
                LabelFormatter = value =>  new System.DateTime((long)value).ToString("t")

        };

And look at this link for formats ToString data formats并查看此链接的格式ToString 数据格式

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM