I have created a chart at run time using win forms (C#.Net Framework 3.5).
I want to make the legend items of this chart interactive.
My requirement is, when a user clicks on Color item present in legend - a color pallet should open and when user selects a color from pallet the selected color should be applied to the outer series data item.
How do I achieve this? In short how do I add a click event handler for a legend item?
Any help is appreciated. NB
Found the answer finally... Posting code here so that it would be helpful for others.
private void HeapStatsChart_MouseDown(object sender, System.Windows.Forms.MouseEventArgs e)
{
HitTestResult result = HeapStatsChart.HitTest(e.X, e.Y);
if (result != null && result.Object != null)
{
// When user hits the LegendItem
if (result.Object is LegendItem)
{
// Legend item result
LegendItem legendItem = (LegendItem)result.Object;
ColorDialog Colour = new ColorDialog();
if (Colour.ShowDialog() == DialogResult.OK)
{
HeapChartColorPref[Convert.ToInt16(legendItem.Name.Substring(4))].color = Colour.Color;
GenerateHeapStatsChart(HeapChartColorPref);
}
}
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With