BarSeries ContextMenu

4 posts, 0 answers
  1. Sandogh
    Sandogh avatar
    3 posts
    Member since:
    Jul 2016

    Posted 03 Jul Link to this post

    Here is a sample BarSeries:

    01.BarSeries barSeries = new BarSeries("Performance", "RepresentativeName");
    02.barSeries.Name = "Q1";
    03.barSeries.DataPoints.Add(new CategoricalDataPoint(177, "Harley"));
    04.barSeries.DataPoints.Add(new CategoricalDataPoint(128, "White"));
    05.barSeries.DataPoints.Add(new CategoricalDataPoint(143, "Smith"));
    06.barSeries.DataPoints.Add(new CategoricalDataPoint(111, "Jones"));
    07.barSeries.DataPoints.Add(new CategoricalDataPoint(118, "Marshall"));
    08.this.radChartView1.Series.Add(barSeries);
    09.BarSeries barSeries2 = new BarSeries("Performance", "RepresentativeName");
    10.barSeries2.Name = "Q2";
    11.barSeries2.DataPoints.Add(new CategoricalDataPoint(153, "Harley"));
    12.barSeries2.DataPoints.Add(new CategoricalDataPoint(141, "White"));
    13.barSeries2.DataPoints.Add(new CategoricalDataPoint(130, "Smith"));
    14.barSeries2.DataPoints.Add(new CategoricalDataPoint(88, "Jones"));
    15.barSeries2.DataPoints.Add(new CategoricalDataPoint(109, "Marshall"));
    16.this.radChartView1.Series.Add(barSeries2);

    How can I

    1) Asign some value (e.g, an Id) to a BarSeries?

    2) Asign a ContextMenu to a BarSeries to get its Id?

  2. Dimitar
    Admin
    Dimitar avatar
    1404 posts

    Posted 04 Jul Link to this post

    Hello  Sandogh,

    Thank you for writing.

    You should use the Name of the series to identify them. The following snippet shows how you can get the series in the ContextMenuOpening event handler and change the menu:
    RadContextMenu menu = new RadContextMenu();
     
    public RadForm1()
    {
        InitializeComponent();
     
        radChartView1.ContextMenuOpening += RadChartView1_ContextMenuOpening;
     
        menu.Items.Add(new RadMenuItem("item1"));
        menu.Items.Add(new RadMenuItem("item2"));
     
    }
    private void RadChartView1_ContextMenuOpening(object sender, ChartViewContextMenuOpeningEventArgs e)
    {
        var mouseLocation = radChartView1.PointToClient(Cursor.Position);
     
        var dataPoint = radChartView1.View.Renderer.HitTest(mouseLocation.X, mouseLocation.Y) as CategoricalDataPoint;
        var series = dataPoint.Presenter as BarSeries;
     
        if (series != null && series.Name == "Q1")
        {
            e.ContextMenu = menu;
        }
    }

    I hope this will be useful. 

    Regards,
    Dimitar
    Telerik
    Check out the Windows Forms project converter, which aids the conversion process from standard Windows Forms applications written in C# or VB to Telerik UI for WinForms.For more information check out this blog post and share your thoughts.
  3. UI for WinForms is Visual Studio 2017 Ready
  4. Sandogh
    Sandogh avatar
    3 posts
    Member since:
    Jul 2016

    Posted 05 Jul in reply to Dimitar Link to this post

    I don't want to assign an Id to a BarSeries. Actually I want to assign some Ids to each Bar. How can I do this?
  5. Dimitar
    Admin
    Dimitar avatar
    1404 posts

    Posted 05 Jul Link to this post

    Hello Sandogh,

    Thank you for writing back.

    To achieve this you need to create a class that inherits CategoricalDataPoint:
    class MyCategoricalDataPoint : CategoricalDataPoint
    {
        public MyCategoricalDataPoint(double value, object category) : base (value, category)
        { }
     
        public int Id { get; set; }
    }

    I hope this will be useful. 

    Regards,
    Dimitar
    Telerik by Progress
    Check out the Windows Forms project converter, which aids the conversion process from standard Windows Forms applications written in C# or VB to Telerik UI for WinForms.For more information check out this blog post and share your thoughts.
Back to Top