Context Menu for RadChartView

2 posts, 0 answers
  1. Erkin
    Erkin avatar
    8 posts
    Member since:
    Dec 2016

    Posted 22 Dec 2016 Link to this post

    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

  2. Hristo
    Admin
    Hristo avatar
    1521 posts

    Posted 23 Dec 2016 Link to this post

    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.
Back to Top