Chart in a Style gives an "axis" error

Jul 17, 2012 at 1:15 PM

I had a UserControl, which included a chart with this code:

<Grid>
	<mschart:Chart x:Name="BarChart"
			DataContext="{Binding Source={StaticResource ResultList}}"
			Style="{StaticResource BarChartStyle}"
			Foreground="{DynamicResource GeneralTextForegroundBrush}"
			ScrollViewer.VerticalScrollBarVisibility="Disabled" Padding="0" BorderBrush="{x:Null}">

		<mschart:Chart.Axes>
			<!-- Shared horizontal axis. -->
			<mschart:CategoryAxis Orientation="X"/>
		</mschart:Chart.Axes>
		
		<mschart:ColumnSeries
				ItemsSource="{Binding}"
				IndependentValueBinding="{Binding Label}"
				DependentValueBinding="{Binding Result}"
				DataPointStyle="{StaticResource ChartDataPointStyle}">

			<mschart:ColumnSeries.DependentRangeAxis>
				<mschart:LinearAxis Orientation="Y" Location="Left" AxisLabelStyle="{StaticResource HiddenAxisLabelStyle}"/>
			</mschart:ColumnSeries.DependentRangeAxis>
		</mschart:ColumnSeries>

	</mschart:Chart>
</Grid>

This worked fine. The axis was replaced to hide it completely (is there any other way?).

Then I changed this control into a custom control, and copied the XAML above to the Template setter. And now I am getting an obscure error:

"Axis location cannot be changed to auto when hosted inside of a series host"

Even if I remove the DependentRangeAxis definition, I get it.

Note, that this error only shows in Blend (after re-loading XAML files and until I press "Build project" - then it shows a column chart as expected). When executed, the program simply shows nothing instead of a chart. Well, if I define a title for the shared axis, it is shown. So I guess, this is the Series compilation that goes wrong.

So, what changed when I moved the XAML from UserControl to a ControlTemplate?

Jul 17, 2012 at 2:38 PM

Update. The runtime issue was a DataContext thing. Having fixed this, the program runs, and only Blend shows some irritating errors - I often see an error about converting System.Runtime to the type I use in DataContext, and once - that a radial axis (?) is not applicable for the given series.

Aug 24, 2012 at 6:17 AM

Hi MikNik, 

 

I am getting same error. can you please let me know how you resolve this error. 

Aug 24, 2012 at 7:41 AM

Well, I guess I never did.

When compiling in Blend (Ctrl+Shift+B), it shows every second time. Every other second time a bar chart is shown, with proper design-time data and possibilities for editing the template and DataPointStyle for the series (though this one sucks as it doesn't use the design-time data, and hence the size of the rectangle is 0, and the colour is "transparent").

So it works - every second time :-)

Blend is in general very sensitive to subtle changes in the code. Rather unstable program, I might say. But the only one we have.