This is a migrated thread and some comments may be shown as answers.

Change Chart Type

1 Answer 136 Views
Chart
This is a migrated thread and some comments may be shown as answers.
Rich
Top achievements
Rank 1
Rich asked on 10 Feb 2011, 12:01 AM

Hi - I have a chart defined in XAML that is bound to an observable collection.  The chart is defined as a line chart.  I would like to make the chart type to be selectable, such as being able to change the chart from a line chart to a bar chart while keeping the data bindings.  I have been trying to accomplish this by changing the series mappings and series definitions in the code behind, but seem to lose the data binding when the new chart is drawn.  How is this accomplished ?   

Thanks
Rich

<Controls:RadChart x:Name="evntChart" Height="150" Width="700"
             Visibility="{Binding ChartVisible, Mode=TwoWay}"
             ItemsSource="{Binding ChartItems}" >
               
 <Controls:RadChart.SeriesMappings>
     <Charting:SeriesMapping LegendLabel="Event Log Errors ">
         <Charting:SeriesMapping.SeriesDefinition>
             <Charting:LineSeriesDefinition />
         </Charting:SeriesMapping.SeriesDefinition>
         <Charting:SeriesMapping.ItemMappings>
             <Charting:ItemMapping DataPointMember="XValue" FieldName="ChartDate" />
             <Charting:ItemMapping DataPointMember="YValue" FieldName="EventCount" />
         </Charting:SeriesMapping.ItemMappings>
     </Charting:SeriesMapping>
 </Controls:RadChart.SeriesMappings>
     <Controls:RadChart.DefaultView>
         <Charting:ChartDefaultView>
             <Charting:ChartDefaultView.ChartLegend>
                 <Charting:ChartLegend  x:Name="chartLegend" Header="Selected Event Log Errors" UseAutoGeneratedItems="True" />                                   
             </Charting:ChartDefaultView.ChartLegend>
             <Charting:ChartDefaultView.ChartArea >
                 <Charting:ChartArea LegendName="chartLegend"  
                                     EnableAnimations="False" 
                                     TransitionControlStyle="{StaticResource TransitionControlStyle}">
                     <Charting:ChartArea.AxisX>
                         <Charting:AxisX  DefaultLabelFormat="dd-MMM" LabelRotationAngle="45">
                         </Charting:AxisX>
                     </Charting:ChartArea.AxisX>
                 </Charting:ChartArea>
             </Charting:ChartDefaultView.ChartArea>
         </Charting:ChartDefaultView>
     </Controls:RadChart.DefaultView>
 </Controls:RadChart>

1 Answer, 1 is accepted

Sort by
0
Yavor
Telerik team
answered on 14 Feb 2011, 09:00 AM
Hello Rich,

One possible option in this case would be the following.
You can declare all the series/item mappings in code behind.
Initially, when the control is initialized, you can declare one set of series mappings. Then, when you need to change these mappings, you can remove the old ones, and declare the new set. This topic elaborates on how to dynamically set the mappings:

http://www.telerik.com/help/wpf/radchart-populating-with-data-data-binding-with-manual-series-mapping.html

Give this approach a try and let me know how it goes.

Kind regards,
Yavor
the Telerik team
Let us know about your Windows Phone 7 application built with RadControls and we will help you promote it. Learn more>>
Tags
Chart
Asked by
Rich
Top achievements
Rank 1
Answers by
Yavor
Telerik team
Share this question
or