簡體   English   中英

時間:2019-05-16 標簽:c#windowsapplicationLiveChartsxaxisdateforma

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

大家好,我在將數據(日期和值)轉換為圖形曲線的項目中工作。 我有 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;
        }

在此處輸入圖片說明

您需要設置 Axis 類的 LabelFormatter 屬性。 像這樣的東西:

 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")

        };

並查看此鏈接的格式ToString 數據格式

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM