I have tried with two approaches to bind the data to piechart and to set the interactivity to the charts.But somehow the interactivity doesnt seems to work.
The xaml that i have is mentioned below.
<
Window x:Class="WpfApplication11.Window1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:telerik="http://schemas.telerik.com/2008/xaml/presentation"
xmlns:telerikChart="clr-namespace:Telerik.Windows.Controls;assembly=Telerik.Windows.Controls.Charting"
Title="Window1" >
<Grid>
<telerikChart:RadChart x:Name="RadChart1" MaxHeight="200" MaxWidth="400">
</telerikChart:RadChart>
</Grid>
</
Window>
and the code behind is somewhat like this:with both the approaches:
//Approach 1
RadChart1.DefaultSeriesDefinition.InteractivitySettings.HoverScope =
InteractivityScope.Item;
RadChart1.DefaultSeriesDefinition.InteractivitySettings.SelectionScope =
InteractivityScope.Item;
RadChart1.DefaultSeriesDefinition.InteractivitySettings.SelectionMode =
ChartSelectionMode.Multiple;
List<Manufacturer> data = new List<Manufacturer>();
data.Add(
new Manufacturer("Toyota", 215));
data.Add(
new Manufacturer("General Motors", 192));
data.Add(
new Manufacturer("Volkswagen", 151));
data.Add(
new Manufacturer("Ford", 125));
data.Add(
new Manufacturer("Honda", 91));
data.Add(
new Manufacturer("Nissan", 79));
data.Add(
new Manufacturer("PSA", 79));
data.Add(
new Manufacturer("Hyundai", 64));
SeriesMapping seriesMapping = new SeriesMapping();
seriesMapping.SeriesDefinition =
new DoughnutSeriesDefinition();
seriesMapping.ItemMappings.Add(
new ItemMapping("Sales", DataPointMember.YValue));
seriesMapping.ItemMappings.Add(
new ItemMapping("Name", DataPointMember.Label));
RadChart1.SeriesMappings.Add(seriesMapping);
RadChart1.ItemsSource = data;
//approach 2 : comment approach 1 to run 2
//DataSeries PieSeriesDefinition = new DataSeries();
//PieSeriesDefinition.Definition = new PieSeriesDefinition();
//PieSeriesDefinition.LegendLabel = "Turnover";
//PieSeriesDefinition.Definition.ItemLabelFormat = "p";
//PieSeriesDefinition.Add(new DataPoint() { YValue = 0.215208267, XCategory = "Jan", LegendLabel = "Jan" });
//PieSeriesDefinition.Add(new DataPoint() { YValue = 0.192960612, XCategory = "Feb", LegendLabel = "Feb" });
//PieSeriesDefinition.Add(new DataPoint() { YValue = 0.079093251, XCategory = "Mar", LegendLabel = "March" });
//PieSeriesDefinition.Add(new DataPoint() { YValue = 0.23456, XCategory = "Apr", LegendLabel = "April" });
//RadChart1.DefaultSeriesDefinition.InteractivitySettings.HoverScope = InteractivityScope.Item;
//RadChart1.DefaultSeriesDefinition.InteractivitySettings.SelectionScope = InteractivityScope.Series;
//RadChart1.DefaultSeriesDefinition.InteractivitySettings.SelectionMode = ChartSelectionMode.Multiple;
//RadChart1.DefaultView.ChartArea.DataSeries.Add(PieSeriesDefinition);
//RadChart1.DefaultView.ChartTitle.Content = "My chart";
//RadChart1.DefaultView.ChartLegend.Header = "My legend";
public class Manufacturer
{
public Manufacturer(string name, int sales)
{
this.Name = name;
this.Sales = sales;
// this.Turnover = turnover;
}
public string Name
{
get;
set;
}
public int Sales
{
get;
set;
}
public int Turnover
{
get;
set;
}
}
Please let me know asap.