I've got a hybrid Chart where the high-level definitions are in XAML, but I build the DataSeries at run-time. I'm getting a case where I have a Legend on the right, but there are no entries there. Here's the XAML:
<telerik:RadChart Name="PowerChart" ItemsSource="{Binding}" > <telerik:RadChart.DefaultView> <telerik:ChartDefaultView> <telerik:ChartDefaultView.ChartArea> <telerik:ChartArea> <telerik:ChartArea.AxisY> <telerik:AxisY Title="Watts"/> </telerik:ChartArea.AxisY> <telerik:ChartArea.AxisX> <telerik:AxisX Title="Time" IsDateTime="True" Step="5" LabelStep="1" DefaultLabelFormat="hh:mm" StepLabelLevelHeight="10"> </telerik:AxisX> </telerik:ChartArea.AxisX> </telerik:ChartArea> </telerik:ChartDefaultView.ChartArea> <telerik:ChartDefaultView.ChartTitle> <telerik:ChartTitle Content="Power"/> </telerik:ChartDefaultView.ChartTitle> </telerik:ChartDefaultView> </telerik:RadChart.DefaultView> <telerik:RadChart.DefaultSeriesDefinition> <telerik:StackedBarSeriesDefinition ShowItemLabels="False"/> </telerik:RadChart.DefaultSeriesDefinition> </telerik:RadChart>Here's the code-behind that populates the chart via a non-default constructor on a Window:
public PowerChartWindow(DateRangeFilter dateRange, IEnumerable<Circuit> circuitList) { InitializeComponent(); // Hide the legend and adjust the title if one circuit if (circuitList.Count() < 2) { PowerChart.DefaultView.ChartLegend.Visibility = System.Windows.Visibility.Collapsed; } else { PowerChart.DefaultView.ChartLegend.Visibility = System.Windows.Visibility.Visible; } // Initialize data series foreach (Circuit c in circuitList) { // Set up the item mappings SeriesMapping circuitMapping = new SeriesMapping(); circuitMapping.ItemMappings.Add(new ItemMapping("Timestamp", DataPointMember.XValue)); circuitMapping.ItemMappings.Add(new ItemMapping("WattsAllPhases",DataPointMember.YValue)); circuitMapping.LegendLabel = c.Name; circuitMapping.FilterDescriptors.Add(new ChartFilterDescriptor("Circuit.Name", typeof(String), Telerik.Windows.Data.FilterOperator.IsEqualTo, c.Name)); // Bind the mappings to the series PowerChart.SeriesMappings.Add(circuitMapping); } } Some of the high points:
- As you see in the XAML, the ItemsMapping is pointed to the DataContext of the Window
- The DataContext is Collection<LoggedACMeterData>
- A LoggedACMeter object has, among other properties, a DateTime Timestamp, a double WattsAllPhases, and a Circuit object which has a String Name property.
- At the moment, the dateRange is ignored.
- I hand in the IEnumerable<Circuit> to the constructor with the idea of building a DataSeries for each Circuit.
- To do the above, I use the ChartFilterDescriptor on each DataSeries to only pull records from the DataContext that matches the circuit name.
So the grid is getting set up properly, with the X-Axis correct, ane the Y-Axis labelled properly, and multiple color-coded series. But the Legend is empty. Thoughts?
Attached is a screen shot of what I get.
David Yon
(on edit: I guess I really mean a SeriesMapping, not a DataSeries as described above)