I have a situation where the number of series visible on a Cartesian Chart will be controlled by some other switch / check box list that selects which series to show on the graph.
I have defined a basic class for each series like so:
public class LineSeriesData
{
public Color Colour { get; set; }
public ObservableCollection<LineDataPoint> DataSet { get; set; }
}
public class LineDataPoint
{
public double Value;
public object Category;
}
The VM for the control that uses the graph will then have a collection of the LineSeriesData class that I'd like to bind to the graph as individual LineSeries like in the documentation example, but I can't work out how the binding would work in the xaml as there's no datatemplate like interface to handle a collection of line series, just individual properties.
<telerik:RadCartesianChart.Series>
<telerik:LineSeries
Stroke="{Binding Colour}"
ValueBinding="Value"
CategoryBinding="Category"
ItemsSource="{Binding DataSet}" />
<telerik:LineSeries
Stroke="{Binding Colour}"
ValueBinding="Value"
CategoryBinding="Category"
ItemsSource="{Binding DataSet}" />
</telerik:RadCartesianChart.Series>
I also tried looping through the collection and adding series manually in the code behind but this doesn't seem to work either. The chart just displays No Data message.
foreach (var item in DataSeries) { var series = new LineSeries { Stroke = item.Colour, ItemsSource = item.DataSet }; series.ValueBinding.PropertyName = "Value"; series.CategoryBinding.PropertyName = "Category"; MyChart.Series.Add(series); };
Is there a way to bind to a collection of series or do we have to have individual properties for each one on the VM? If they have to be individual properties, how would I go about hiding / showing a series?
Thanks!