I want to make the y axis the independent axis, i.e. turning the horizontal rendering of a line series into a vertical one. This is the code that I started with:
<Window x:Class="Wpf.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:charting="clr-namespace:System.Windows.Controls.DataVisualization.Charting;assembly=System.Windows.Controls.DataVisualization.Toolkit"
Title="MainWindow" Height="350" Width="525">
<Grid>
<charting:Chart>
<charting:Chart.Axes>
<charting:LinearAxis Orientation="X" ShowGridLines="True" Name="xAxis" />
<charting:LinearAxis Orientation="Y" ShowGridLines="True" Name="yAxis" />
</charting:Chart.Axes>
<charting:LineSeries
Name="lineSeries"
ItemsSource="{Binding}"
IndependentValuePath="Indep"
DependentValuePath="Dep">
</charting:LineSeries>
</charting:Chart>
</Grid>
</Window>
First I tried adding
<charting:LineSeries.IndependentAxis>
<charting:LinearAxis Orientation="Y" />
</charting:LineSeries.IndependentAxis>
<charting:LineSeries.DependentRangeAxis>
<charting:LinearAxis Orientation="X" />
</charting:LineSeries.DependentRangeAxis>
This results in a System.InvalidOperationException
with a message saying
Assigned independent axis cannot be used. This may be due to an unset Orientation property for the axis.
However, when swapping the values of "X"
and "Y"
in the above snippet, there's no exception and everything works fine, except of course that the axes aren't oriented the way I want them.
Next thing I tried is doing it programmatically:
lineSeries.IndependentAxis = yAxis;
lineSeries.DependentRangeAxis = xAxis;
which gives me the same exception. Again, when swapping xAxis
and yAxis
in the statements above, there's no exception.
Any idea how to get what I want?