Reputation: 67
I am confounded by the XAML markup in general and especially for the chart toolkit and would greatly appreciate help sorting it out. I have successfully created a chart with the X axis showing timeline and Y axis showing a value using XAML below:
<chartingToolkit:Chart HorizontalAlignment="Left" Margin="44,12,0,0" Name="chart1" VerticalAlignment="Top" Height="521" Width="826">
<chartingToolkit:Chart.Axes>
<chartingToolkit:DateTimeAxis IntervalType ="Hours" Interval="1">
<chartingToolkit:DateTimeAxis.AxisLabelStyle>
<Style TargetType="chartingToolkit:DateTimeAxisLabel">
<Setter Property="Template">
<Setter.Value>
<Setter Property="StringFormat" Value="{}{0:H}" />
</Setter.Value>
</Setter>
</Style>
</chartingToolkit:DateTimeAxis.AxisLabelStyle>
</chartingToolkit:DateTimeAxis>
</chartingToolkit:Chart.Axes>
<chartingToolkit:LineSeries x:Name="LineSeries1" DependentValuePath="Value" IndependentValuePath="Key" ItemsSource="{Binding}">
<chartingToolkit:LineSeries.DataPointStyle>
<Style TargetType="chartingToolkit:LineDataPoint">
<Setter Property="Visibility" Value="Collapsed"/>
<Setter Property="Background" Value="violet"/>
<Setter Property="Opacity" Value="0" />
</Style>
</chartingToolkit:LineSeries.DataPointStyle>
</chartingToolkit:LineSeries>
</chartingToolkit:Chart>
In the code-behind I populate a dictiory declared as Dictionary<TimeSpan, float> Dict = new Dictionary<TimeSpan, float>();
with values every minute for 2 hours (60 values) and set the datacontext for lineseries1
to the dictionary as such: LineSeries1.DataContext = Dict.
The graph draws beautifully, However as apparent from my futile attempt in the XAML. I need the X label and tick marks to show up only once per hour and not once per minute and I need it to show only hours and not minutes and seconds. My XAML code above for adjusting the interval and formatting of the label does not work. I would appreciate any pointer to steer me in the right direction.
Thanks, Kalory
Upvotes: 2
Views: 5099
Reputation: 102
It should work as you planned if you add orientation to your DateTimeAxis, like this:
<chartingToolkit:DateTimeAxis Orientation="X" IntervalType ="Hours" Interval="1">
I don't know why it makes difference, but it seem it does...
Upvotes: 1