Get data object for Bar or Pie Series in Mouse event

Charts for WPF Forum

Posted 10 years ago by Bill L
Version: 14.2.0610
Avatar

Hey,

Is it possible to get the data that is used to construct the particular Bar or Pie Series when a mouse is left clicked or hovered over a chart?  If I have a hiearchical Pie series, I would like to get access to the Parent data when a child pie slice shape is mouse clicked or simply get the data object that was used to draw the pie slice.

 

Best regards,

Bill

Comments (5)

Posted 10 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar

Hi Bill,

If you have a PieSlice object and want to know the original data used to generate it, you can look at its OriginalItems property.  It doesn't look like the nested child pie slice data tracks any references back up to the parent pie slices, so you would have to store such a reference in your data used to construct the pie slices and then traverse up after looking at the OriginalItems.  Also for bar charts, I don't believe the individual Border objects plotted for bars get passed the original data.


Actipro Software Support

Posted 10 years ago by Bill L
Avatar

Hey,

What I can't figure out is how to get access to the PieSlice object from a mouse event.  It seems that I can only get access to the DonutChart object for example and not a PieSlice within a series.  I have tried adding event handlers to the PieSeries defined in xaml, but they will not fire.  The only event handlers I can get to fire are on the Chart definition itself.

Best regards,

Bill

Posted 10 years ago by Bill L
Avatar

Hey,

I was able to get access to the PieSlice in the mouse event handler on the DonutChart instance.

Best regards,

Bill

Posted 10 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar

Hi Bill,

Great, yes I was going to say that this sort of code should work since the PieSlice is an element:

protected override void OnMouseMove(System.Windows.Input.MouseEventArgs e) {
	var element = e.OriginalSource as UIElement;
	if (element != null) {
		var slice = VisualTreeHelperExtended.GetCurrentOrAncestor(element, typeof(PieSlice)) as PieSlice;
		if (slice != null) {
			// Process slice here
		}
	}

	base.OnMouseMove(e);
}

In the future we may add interaction events as well to make this a bit more straightforward.


Actipro Software Support

Posted 10 years ago by Bill L
Avatar

Hey,

I ended up doing pretty much the same thing using a VisualTree helper.  What wasn't straight forward is being able to get a PieSlice based on a click in the Legend control as their isn't any relational data cached other than the label text of the LegendKey.

Best regards,

Bill

The latest build of this product (v24.1.2) was released 2 days ago, which was after the last post in this thread.

Add Comment

Please log in to a validated account to post comments.