Q: I want to tell which piece is being clicked in a chart. How to know this?

A: When hit testing you should call the HitTest method of the chart. It returns you a list of the elements of the chart that contained the specified point. If one of them is PiePiece you can tell its index and the index of its series by its properties. Here is how to do this:

 private void pieChart1_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
 List result = pieChart1.HitTest(e.GetPosition(pieChart1));
 foreach (ChartElement element in result)
 if (element is PiePiece)
 int index = (element as PiePiece).PieceIndex;
 int seriesIndex = (element as PiePiece).SeriesIndex;

 PieSeries series = pieChart1.Series[seriesIndex] as PieSeries;
 double pieceData = double.Parse(series.Data[index].ToString());

 MessageBox.Show(pieceData + " ### " + index);


Copyright © 2001-2022 MindFusion LLC. Alle Rechte vorbehalten.
Nutzungsbedingungen - Kontakt