Hi,
When a chart is created, I add event listeners to the individual pie slices for interactivity. However, it's possible for the user to change the current data set, which may add or remove slices from this pie chart. I've been unable to figure out how to listen for a change in the pie chart so that I can appropriately add/remove event listeners. Is there some method for the pie series I can listen to that will accomplish this? PieSeries.LayoutUpdated occurs whenever anything is highlighted, resized, etc. I tried to just listen for when the data collection itself changed, but at this time the PieSeries itself hadn't yet updated.
Thank you!
When a chart is created, I add event listeners to the individual pie slices for interactivity. However, it's possible for the user to change the current data set, which may add or remove slices from this pie chart. I've been unable to figure out how to listen for a change in the pie chart so that I can appropriately add/remove event listeners. Is there some method for the pie series I can listen to that will accomplish this? PieSeries.LayoutUpdated occurs whenever anything is highlighted, resized, etc. I tried to just listen for when the data collection itself changed, but at this time the PieSeries itself hadn't yet updated.
Thank you!
4 Answers, 1 is accepted
0
Hi Stephen,
I have attached a sample project demonstrating how you can attach a highlight on mouse enter behavior to the pie slices using an attached property. Fill free to modify it as per your requirements.
Regards,
Petar Kirov
Telerik
I have attached a sample project demonstrating how you can attach a highlight on mouse enter behavior to the pie slices using an attached property. Fill free to modify it as per your requirements.
Regards,
Petar Kirov
Telerik
TRY TELERIK'S NEWEST PRODUCT - EQATEC APPLICATION ANALYTICS for SILVERLIGHT.
Learn what features your users use (or don't use) in your application. Know your audience. Target it better. Develop wisely.
Sign up for Free application insights >>
Learn what features your users use (or don't use) in your application. Know your audience. Target it better. Develop wisely.
Sign up for Free application insights >>
0
Stephen
Top achievements
Rank 1
answered on 21 Oct 2013, 09:27 PM
Hi,
Thank you for your detailed response, but the example you gave does not do what I require.
I need to detect when the data changes for a single pie chart slice so that I can update that slice's behavior as needed. In your example, the "OnAttached" function is called for each slice when the pie chart is initially loaded, but if the data is modified, neither the OnAttached or OnDetaching methods are called. For example, if I wanted to change the color of the highlight on mouse enter depending on the chart data, I would be unable to do so.
Thanks for your help so far.
Thank you for your detailed response, but the example you gave does not do what I require.
I need to detect when the data changes for a single pie chart slice so that I can update that slice's behavior as needed. In your example, the "OnAttached" function is called for each slice when the pie chart is initially loaded, but if the data is modified, neither the OnAttached or OnDetaching methods are called. For example, if I wanted to change the color of the highlight on mouse enter depending on the chart data, I would be unable to do so.
Thanks for your help so far.
0
Hi Stephen,
You can use PieSeries' SliceStyleSelector property to instantiate a custom StyleSelector. The SelectStyle method of your custom StyleSelector will be called when:
Here's an example:
Please note that the Paths that represent the individual pie slices are recycled (when a datapoint is removed the visual element is not released, but is used when a new datapoint is added) and that's why the OnDetaching() method of the Behavior was not called.
Regards,
Petar Kirov
Telerik
You can use PieSeries' SliceStyleSelector property to instantiate a custom StyleSelector. The SelectStyle method of your custom StyleSelector will be called when:
- An item from the PieSeries ItemsSource is removed
- An item is added to the PieSeries ItemsSource
- The value of an existing item in the ItemsSource is changed
Here's an example:
public
class
PieSliceStyleSelector : StyleSelector
{
public
override
Style SelectStyle(
object
item, DependencyObject container)
{
var dp = item
as
PieDataPoint;
var series = container
as
PieSeries;
var chart = series.ParentOfType<RadPieChart>();
var paletteEntries = chart.Palette.GlobalEntries;
var slice = series.ChildrenOfType<Path>()
.Where(p => p.DataContext == dp).First();
slice.Fill = paletteEntries[dp.Index % paletteEntries.Count].Fill;
//Attach to slice events...
return
base
.SelectStyle(item, container);
//or return custom style
}
}
Please note that the Paths that represent the individual pie slices are recycled (when a datapoint is removed the visual element is not released, but is used when a new datapoint is added) and that's why the OnDetaching() method of the Behavior was not called.
Petar Kirov
Telerik
TRY TELERIK'S NEWEST PRODUCT - EQATEC APPLICATION ANALYTICS for SILVERLIGHT.
Learn what features your users use (or don't use) in your application. Know your audience. Target it better. Develop wisely.
Sign up for Free application insights >>
Learn what features your users use (or don't use) in your application. Know your audience. Target it better. Develop wisely.
Sign up for Free application insights >>
0
Stephen
Top achievements
Rank 1
answered on 28 Oct 2013, 05:04 PM
Thank you so much, this did exactly what I wanted. Cheers!