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

hover interactivity in pie series chart

1 Answer 119 Views
Chart
This is a migrated thread and some comments may be shown as answers.
anurag
Top achievements
Rank 1
anurag asked on 16 Nov 2010, 05:50 AM
Hi ,
 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.

1 Answer, 1 is accepted

Sort by
0
Evan
Telerik team
answered on 17 Nov 2010, 02:56 PM
Hi anurag,

In looking at the code that you provided, I've found one slight issue which will impact getting the interactivity settings working with the DoughnutSeriesDefinition (from approach 1).  In code, you are setting the InteractivitySettings of the DefaultSeriesDefinition, but then creating a new series definition to apply to the series mapping.  In this case, the default series would have these settings but the newly created one has no interactivity set.

Below is a revision on your 'Approach 1' with interactivity settings being applied to the DoughnutSeriesDefinition instead:

//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();
  
DoughnutSeriesDefinition dsd = new DoughnutSeriesDefinition();
dsd.InteractivitySettings.HoverScope = InteractivityScope.Item;
dsd.InteractivitySettings.SelectionMode = ChartSelectionMode.Single;
  
seriesMapping.SeriesDefinition = dsd; 
  
seriesMapping.ItemMappings.Add(new ItemMapping("Sales", DataPointMember.YValue)); 
  
seriesMapping.ItemMappings.Add(new ItemMapping("Name", DataPointMember.Label)); 
  
RadChart1.SeriesMappings.Add(seriesMapping);
  
RadChart1.ItemsSource = data;

Let us know how that works and if you have any other questions.

Best wishes,
Evan
the Telerik team
Tags
Chart
Asked by
anurag
Top achievements
Rank 1
Answers by
Evan
Telerik team
Share this question
or