0
votes

Im using the System.Windows.Controls.DataVisualization.Toolkit.dll supplied by the WPFToolkit.

I have a chart displaying a list of dates on the X Axis and integers on the Y.

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>

When i have the chart containing enough data it displays each point on the X axis as a Date. ie. 2016-01-06, 2016-01-07, 2016-01-08 etc.

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

How can i force it to only display date intervals on the X.

1

1 Answers

2
votes

I figured it out. I need to specify the Interval and IntervalType within the LineSeries for the IndependantAxis.

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