Profile Picture

How to detect clicked legend data item?

Posted By Alexandr S. 12 Years Ago
Author
Message
Alexandr S.
Posted 12 Years Ago
View Quick Profile
Junior Member

Junior Member (22 reputation)Junior Member (22 reputation)Junior Member (22 reputation)Junior Member (22 reputation)Junior Member (22 reputation)Junior Member (22 reputation)Junior Member (22 reputation)Junior Member (22 reputation)Junior Member (22 reputation)

Group: Forum Members
Last Active: 8 Years Ago
Posts: 23, Visits: 6
I need to detect what legend data item was clicked by mouse. Legend panel is in automatic mode. How to do this?

Nevron Support
Posted 12 Years Ago
View Quick Profile
Supreme Being

Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)

Group: Forum Members
Last Active: Last Week
Posts: 3,054, Visits: 4,009

Hi Alexander,

That's a bit tricky as the legend item index is not exposed from the hit test result - you need to obtain the parent collection and find the item there:

  private void Form1_Load(object sender, EventArgs e)
  {
   NChart chart = nChartControl1.Charts[0];

   for (int i = 0; i < 10; i++)
   {
    NBarSeries bar = new NBarSeries();
    bar.Values.Add(10);
    chart.Series.Add(bar);
   }

   nChartControl1.MouseDown += new MouseEventHandler(nChartControl1_MouseDown);
  }

  void nChartControl1_MouseDown(object sender, MouseEventArgs e)
  {
   NHitTestResult result = nChartControl1.HitTest(e.X, e.Y);

   if (result.ChartElement == ChartElement.LegendDataItem)
   {
    NLegendItemCellData cell = result.LegendDataItem;

    NChartElementComposite parent = (NChartElementComposite)cell.ParentNode;
    int index = parent.IndexOfChild(cell);

    MessageBox.Show("Legend data item [" + index.ToString() + "]");
   }
  }



Best Regards,
Nevron Support Team



Alexandr S.
Posted 12 Years Ago
View Quick Profile
Junior Member

Junior Member (22 reputation)Junior Member (22 reputation)Junior Member (22 reputation)Junior Member (22 reputation)Junior Member (22 reputation)Junior Member (22 reputation)Junior Member (22 reputation)Junior Member (22 reputation)Junior Member (22 reputation)

Group: Forum Members
Last Active: 8 Years Ago
Posts: 23, Visits: 6
thank you!



Similar Topics


Reading This Topic