Hi,
I am designing a wizard which allows a user to style a chart, so it's similar to the sample (XamDataChart > Display > Gallery - Category Series) they can choose the type of line series they want, it all works fine but the issue I'm having is that the legend data seems to be shared across all of the charts.
So I have 10 or so charts which are using the same legend (same as the sample) and I'm toggling visibility of the charts which I would expect the legend data to be changed based on that.
<ig:Legend x:Name="Legend" />
However I'm not binding the data like in the sample it's getting the data from the chart
How can I get around this so that the legend only shows data for that chart?
Thanks, Grant
Hi Grant,
You should still be able to implement this with MVVM. Rather than running the Visibility code in code behind, place it into a Behavior<T> and then attach the behavior to the XamDataCharts. You can then listen for the Visibility changed event on the XamDataChart and hide the series when needed.
Thanks for this it works as I wanted, although I was ideally going to implement the solution using the mvvm pattern
Based on your solution I thought it would be straight forward but it's not binding properly with the visibility on the series, I think it can only be set after the initialization
In the Gallery - Category Series sample there is a function in the code-behind file called ChangeChartsVisibility(). In this function it is not only setting the XamDataChart's Visibility but it is also looping through the chart's Series collection and setting the visibility on each series as well. This is what causes the series to become hidden from the Legend. Just setting the XamDataChart's Visibility will not hide the data from the legend.
I have attached a simple sample application that switches between a Line Series and Column Series. You will see that the legend data is changed as well.