gpt4 book ai didi

c# - 基本 WPF LiveCharts DateTime 示例不起作用

转载 作者:太空狗 更新时间:2023-10-30 00:38:12 32 4
gpt4 key购买 nike

我尽可能地遵循了 Live Charts TimeDate 基本示例,但似乎无法正确显示 X 轴。

https://lvcharts.net/App/examples/v1/wpf/Date%20Time

我的主窗口代码

public partial class MainWindow : Window
{
public Func<double, string> Formatter { get; set; }

public MainWindow()
{
InitializeComponent();

var dayConfig = Mappers.Xy<DateModel>()
.X(dateModel => dateModel.DateTime.Ticks / TimeSpan.FromDays(1).Ticks)
.Y(dateModel => dateModel.Value);

SeriesCollection Series = new SeriesCollection(dayConfig)
{
new LineSeries
{
Title = "Google Rank",

Values = new ChartValues<DateModel>
{
new Wpf.CartesianChart.Using_DateTime.DateModel
{
DateTime = System.DateTime.UtcNow,
Value = 5
},
new Wpf.CartesianChart.Using_DateTime.DateModel
{
DateTime = System.DateTime.UtcNow.AddDays(1),
Value = 9
},
new Wpf.CartesianChart.Using_DateTime.DateModel
{
DateTime = System.DateTime.UtcNow.AddDays(2),
Value = 4
}
},

Fill = Brushes.Transparent,

},
};

Formatter = value => new System.DateTime((long)(value * TimeSpan.FromDays(1).Ticks)).ToString("t");

RankGraph.Series = Series;
}
}

我的主窗口上的 XAML

<Grid>
<lvc:CartesianChart x:Name="RankGraph" Series="{Binding Series}">
<lvc:CartesianChart.AxisX>
<lvc:Axis LabelFormatter="{Binding Formatter}"></lvc:Axis>
</lvc:CartesianChart.AxisX>
</lvc:CartesianChart>
</Grid>

日期模型对象

namespace Wpf.CartesianChart.Using_DateTime
{
public class DateModel
{
public DateTime DateTime { get; set; }
public double Value { get; set; }
}
}

这会产生以下日期困惑的...

enter image description here

最佳答案

您忘记设置数据上下文:

DataContext = this;

enter image description here

关于c# - 基本 WPF LiveCharts DateTime 示例不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43985282/

32 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com