Hi Santosh,
You can easily display a context menu in response to mouse click event - the following code snippet shows how to show a dynamic context menu that contains two elements in case you click on a bar or the rest of the control:
private void Form1_Load(object sender, EventArgs e)
{
NChart chart = nChartControl1.Charts[0];
NBarSeries bar = new NBarSeries();
bar.Values.Add(10);
bar.Values.Add(20);
bar.Values.Add(30);
chart.Series.Add(bar);
nChartControl1.MouseClick += new MouseEventHandler(nChartControl1_MouseClick);
}
void nChartControl1_MouseClick(object sender, MouseEventArgs e)
{
NHitTestResult hitTest = nChartControl1.HitTest(e.X, e.Y);
ContextMenu menu = new ContextMenu();
if (hitTest.ChartElement == ChartElement.DataPoint)
{
MenuItem barMenuItem = new MenuItem();
barMenuItem.Click +=new EventHandler(barMenuItem_Click);
barMenuItem.Tag = hitTest.DataPointIndex;
barMenuItem.Text = "Toggle Fill";
menu.MenuItems.Add(barMenuItem);
}
MenuItem editorMenuItem = new MenuItem();
editorMenuItem.Click +=new EventHandler(editorMenuItem_Click);
editorMenuItem.Text = "Show Editor...";
menu.MenuItems.Add(editorMenuItem);
menu.Show(nChartControl1, new Point(e.X, e.Y));
}
void editorMenuItem_Click(object sender, EventArgs e)
{
nChartControl1.ShowEditor();
}
void barMenuItem_Click(object sender, EventArgs e)
{
NChart chart = nChartControl1.Charts[0];
NBarSeries bar = (NBarSeries)chart.Series[0];
int barIndex = (int)((MenuItem)sender).Tag;
if (bar.FillStyles[barIndex] == null)
{
bar.FillStyles[barIndex] = new NColorFillStyle(Color.Red);
}
else
{
bar.FillStyles[barIndex] = null;
}
nChartControl1.Refresh();
}
Hope this helps - let us know if you meet any problems.
Best Regards,
Nevron Support Team