[英]WPF Toolkit DataVisualization. Specifying the X axis interval
Im using the System.Windows.Controls.DataVisualization.Toolkit.dll supplied by the WPFToolkit. 我正在使用WPFToolkit提供的System.Windows.Controls.DataVisualization.Toolkit.dll。
I have a chart displaying a list of dates on the X Axis and integers on the Y. 我有一个图表,在X轴上显示日期列表,在Y上显示整数。
XAML: XAML:
<DVC:Chart Canvas.Top="80" Canvas.Left="10" Name="mcChart" Background="LightSteelBlue" Margin="12">
<DVC:Chart.Series>
<DVC:LineSeries Title="Lines" IndependentValueBinding="{Binding Path=Key}" DependentValueBinding="{Binding Path=Value}" />
</DVC:Chart.Series>
</DVC:Chart>
Code: 码:
ObservableCollection<KeyValuePair<DateTime, int>> Data = new ObservableCollection<KeyValuePair<DateTime, int>>();
Data.Add(new KeyValuePair<DateTime, int>(DateTime.Now.AddDays(-10), 100));
Data.Add(new KeyValuePair<DateTime, int>(DateTime.Now.AddDays(-9), 200));
Data.Add(new KeyValuePair<DateTime, int>(DateTime.Now.AddDays(-8), 500));
((LineSeries)mcChart.Series[0]).ItemsSource = Data;
Im binding the mcChart's ItemsSource to an ObservableCollection<int, DateTime>
我将mcChart的ItemsSource绑定到
ObservableCollection<int, DateTime>
When i have the chart containing enough data it displays each point on the X axis as a Date. 当我的图表包含足够的数据时,它将X轴上的每个点显示为日期。 ie.
即。 2016-01-06, 2016-01-07, 2016-01-08 etc.
2016-01-06、2016-01-07、2016-01-08等
However if i only have a few points displayed on the chart the intervals split up into hours. 但是,如果图表上仅显示几个点,则时间间隔会分成几个小时。 ie.
即。 20:00, 00:00, 04:00, 08:00, 12:00, 16:00, 20:00
20:00、00:00、04:00、08:00、12:00、16:00、20:00
How can i force it to only display date intervals on the X. 我如何强制它仅在X上显示日期间隔。
I figured it out. 我想到了。 I need to specify the Interval and IntervalType within the LineSeries for the IndependantAxis.
我需要在LineSeries中为IndependantAxis指定Interval和IntervalType。
<DVC:Chart Canvas.Top="80" Canvas.Left="10" Name="mcChart" Background="LightSteelBlue" Margin="12">
<DVC:Chart.Series>
<DVC:LineSeries Title="Lines" IndependentValueBinding="{Binding Path=Key}" DependentValueBinding="{Binding Path=Value}">
<DVC:LineSeries.IndependentAxis>
<DVC:DateTimeAxis Orientation="X" Title="Date" Interval="1" IntervalType="Days" />
</DVC:LineSeries.IndependentAxis>
</DVC:LineSeries>
</DVC:Chart.Series>
</DVC:Chart>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.