This is a migrated thread and some comments may be shown as answers.
BarSeries ContextMenu
3 Answers 6 Views
This is a migrated thread and some comments may be shown as answers.
Sandogh
Top achievements
Rank 1
Sandogh asked on 03 Jul 2016, 12:13 PM

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?

3 Answers, 1 is accepted

Sort by
0
Dimitar
Telerik team
answered on 04 Jul 2016, 10:31 AM
Hello  ,

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.
0
Sandogh
Top achievements
Rank 1
answered on 05 Jul 2016, 12:09 PM
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?
0
Dimitar
Telerik team
answered on 05 Jul 2016, 02:01 PM
Hello ,

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.
Asked by
Sandogh
Top achievements
Rank 1
Answers by
Dimitar
Telerik team
Sandogh
Top achievements
Rank 1
Share this question
or