WebChart Pressed Event

Hi, everyone!

I build my linear chart with this code:

Var mySet1 As New WebChartLinearDataset("Series 1", Color.Red, True, 5)
mySet1.ChartType = WebChartLinearDataset.ChartTypes.Bar
mySet1.Tag = "Series1"

Charts1.AddDataset(mySet1)

Var mySet2 As New WebChartLinearDataset("Series 2", Color.Blue, True, 12)
mySet2.ChartType = WebChartLinearDataset.ChartTypes.Bar
mySet2.Tag = "Series2"

Charts1.AddDataset(mySet2)

Note the Tag property is a necessity because in a linear chart, the index parameter always returns 0 in the Pressed event, unlike if the chart type is a pie, index works perfectly.

In my chart’s Pressed event, I would like to raise an event of the parent container. However, since dataset parameter is defined as ChartData, the Tag property is not exposed.

I would like to know what series is clicked by the user.

Thank you in advance!

If you set a Break in your Pressed event, you will be able to see exactly the Class being received as the dataset parameter:

In this case, is a WebChartLinearDataset, which is the same type as mySet1 and mySet2.

You can cast (see Type Casting) and use the Tag property. Here is an example:

Var tag As String = WebChartLinearDataset(dataset).Tag
RaiseEvent ExampleEvent(tag)
1 Like

Gabriel Ludosanu recently posted a blog post covering Type Casting:
From Iteration to Interaction with Type Casting

Thank you, Ricardo! This is what I need.

1 Like