I have this XAML from a sample:
<chart:RadChart.SeriesMappings>
<charting:SeriesMapping LegendLabel="Population">
<charting:ItemMapping DataPointMember="YValue" FieldName="Population" />
<charting:ItemMapping DataPointMember="XCategory" FieldName="Country" />
</charting:SeriesMapping>
<charting:SeriesMapping LegendLabel="Vehicles in circulation" ItemsSource="{Binding DataSource2}">
<charting:ItemMapping DataPointMember="YValue" FieldName="Vehicles" />
<charting:ItemMapping DataPointMember="XCategory" FieldName="Country" />
</charting:SeriesMapping>
<charting:SeriesMapping LegendLabel="Road network length (km)" ItemsSource="{Binding DataSource3}">
<charting:SeriesMapping.SeriesDefinition>
<charting:BarSeriesDefinition AxisName="Secondary" ItemLabelFormat="#Y{0,.# k}" />
</charting:SeriesMapping.SeriesDefinition>
<charting:ItemMapping DataPointMember="YValue" FieldName="RoadNetwork" />
<charting:ItemMapping DataPointMember="XCategory" FieldName="Country" />
</charting:SeriesMapping>
</chart:RadChart.SeriesMappings>
Right now I have the entire chart binded to a single source, but I can see in the example it’s possible to bind each mapping to a different source:
<charting:SeriesMapping LegendLabel="Vehicles in circulation" ItemsSource="{Binding DataSource2}">
I am trying to find out how to do this programatically. Because my mappings are dynamic (I don’t know if I’ll have 1 or 10 or any number of mappings) I am trying to set each one in the code behind.
Here is the answer to this one:
Where mapping is a new SeriesMapping()