Nevron Forum

Finding Legend data index on a Mouse Click

https://www.nevron.com/Forum/Topic8882.aspx

By Rick Merritt - Friday, January 9, 2015

I am trying to turn line series on and off based on a user clicking on the legend data item.  Unfortunately the hit test always returns a 0 (zero) no matter which cell I click on in the legend.  Any help would be appreciated.


By Nevron Support - Thursday, January 15, 2015

So far it looks like a bug in the control we'll investigate it further and fix it for the upcoming 2015 release.
By Rick Merritt - Thursday, January 15, 2015

Any Idea for a work-around?
By Rick Merritt - Tuesday, May 5, 2015

Was this ever fixed in the latest release?
By Nevron Support - Wednesday, May 6, 2015

Hi Rick,

This issue is not present in the 2015 release - we just tested with the following code and it was working OK:

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

NBarSeries bar = new NBarSeries();
bar.Legend.Mode = SeriesLegendMode.DataPoints;

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

chart.Series.Add(bar);

nChartControl1.MouseClick += new MouseEventHandler(nChartControl1_MouseClick);
}

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

if (result.ChartElement == ChartElement.LegendDataItem)
{
int index = result.LegendDataItemIndex;
}
}