Problem binding multiple axes

Charts for WPF Forum

Posted 5 years ago by David Christensen
Version: 14.1.0602
Platform: .NET 4.5
Environment: Windows 8 (64-bit)
Avatar

I am attempting to draw a chart with multiple axes:

 

<charts:XYChart >
<charts:XYChart.XAxes>
<charts:XYDoubleAxis AreMajorTicksVisible="True" AreMinorTicksVisible="True" TickMajorInterval="10" TickMinorInterval="5" AreLabelsVisible="True" />
</charts:XYChart.XAxes>
<charts:XYChart.YAxes>
<charts:XYDoubleAxis Maximum="4000" Minimum="0" x:Name="FileAxis" Position="NearEdge" Title="Files" AreLabelsVisible="True" AreMajorTicksVisible="True" AreMinorTicksVisible="True" />
<charts:XYDoubleAxis Maximum="4000" Minimum="0" x:Name="EffortAxis" Position="FarEdge" Title="Effort" AreLabelsVisible="True" AreMajorTicksVisible="True" AreMinorTicksVisible="True" />
</charts:XYChart.YAxes>
<charts:LineSeries x:Name="FileSeries" ItemsSource="{Binding Path=CumulativeStages}" XPath="StageNumber" YPath="FileCount"
YAxis="{Binding ElementName=FileAxis}" >

</charts:LineSeries>
<charts:LineSeries x:Name="EffortSeries" ItemsSource="{Binding Path=CumulativeStages}" XPath="StageNumber" YPath="CodeEffort"
YAxis="{Binding ElementName=EffortAxis}" />
</charts:XYChart>

 

However I only get a default axis and two databinding errors:

System.Windows.Data Error: 4 : Cannot find source for binding with reference 'ElementName=FileAxis'. BindingExpression:(no path); DataItem=null; target element is 'LineSeries' (Name='FileSeries'); target property is 'YAxis' (type 'XYAxisBase')
System.Windows.Data Error: 4 : Cannot find source for binding with reference 'ElementName=EffortAxis'. BindingExpression:(no path); DataItem=null; target element is 'LineSeries' (Name='EffortSeries'); target property is 'YAxis' (type 'XYAxisBase')

 

Any suggestions?

 

Thanks

 

DC

Comments (3)

Posted 5 years ago by David Christensen
Avatar

In fact we have discovered that this is only a problem if the chart is within a tab control.  Outside a tab control it works just fine.

Curious.

Posted 5 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar

Hi David,

I think what is happening here is that for performance reasons, we probably have an optimization to not fully construct the chart until it is in the visual tree.  We also add all the series, etc. to the logical tree so that ElementName bindings can work.  The bindings seem to work on the first (displayed) tab, but for a chart on a second or other initially-hidden tab, they fail.  This is probably due to the chart not being fully constructed.

We found a workaround though that seems to work for any failing bindings in this scenario.  Say this binding is failing:

YAxis="{Binding ElementName=FileAxis}"

Change it to:

YAxis="{Binding Source={x:Reference FileAxis}}"


Actipro Software Support

Posted 5 years ago by David Christensen
Avatar

Thank you, this is working (at run time).

At Design Time, the statement gets a blue squiggly line underneath and Visual Studio (2013, update 2) gives a message saying "Object reference not set to an instance of an object".   I can live with this, but if we can avoid this too it would be even better!

Thanks again for the speedy workaround

 

David

The latest build of this product (v2019.1 build 0681) was released 17 days ago, which was after the last post in this thread.

Add Comment

Please log in to a validated account to post comments.