This is a migrated thread and some comments may be shown as answers.

Context Menu for RadChartView

1 Answer 155 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Erkin
Top achievements
Rank 1
Erkin asked on 22 Dec 2016, 09:06 PM

Hello,

I was wondering if it is possible to use the Context Menu on a Line series radchartview? I want to be able to right click on a Line series within the chart and open up a context menu that corresponds to that line and I also want to be able to do the same thing on the legend except with a separate context menu.

Any ideas?

 

Thank you,

 

Erkin

1 Answer, 1 is accepted

Sort by
0
Hristo
Telerik team
answered on 23 Dec 2016, 03:35 PM
Hello Erik,

Thank you for writing.

You can enable selection in RadChartView and detect the clicked data points: RadChartView | Selection.
Handling clicks on the series is, however, more tricky. A similar question has been discussed in the following forum thread: http://www.telerik.com/forums/how-to-select-a-series.

Regarding the legends, you can handle the MouseDown event of your chart and assign a particular context menu depending on the clicked element. Please check my code snippet below: 
private void radChartView1_MouseDown(object sender, MouseEventArgs e)
{
    if (e.Button != MouseButtons.Right)
    {
        return;
    }
 
    RadChartView chart = (RadChartView)sender;
    RadElement element = chart.ElementTree.GetElementAtPoint(e.Location);
    LegendItemElement itemElement = chart.ElementTree.GetElementAtPoint(e.Location) as LegendItemElement;
    if (itemElement == null)
    {
        RadElement parent = element.Parent;
        while (parent != null)
        {
            if (parent is LegendItemElement)
            {
                itemElement = (LegendItemElement)parent;
                break;
            }
 
            parent = parent.Parent;
        }
    }
 
    if (itemElement != null)
    {
        this.radContextMenu1.Items.Clear();
        this.radContextMenu1.Items.Add(new RadMenuItem(((LineSeries)itemElement.LegendItem.Element).LegendTitle));
        this.radContextMenu1.Show(Control.MousePosition);
    }
}

I hope this helps. Should you have further questions please do not hesitate to write back.

Regards,
Hristo
Telerik by Progress
Try our brand new, jQuery-free Angular 2 components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
Tags
General Discussions
Asked by
Erkin
Top achievements
Rank 1
Answers by
Hristo
Telerik team
Share this question
or