单击图表时如何获得图表的系列名称,图表名称 [英] How to get series name, Chartarea name of chart when chart is clicked
本文介绍了单击图表时如何获得图表的系列名称,图表名称的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在使用MS图表堆积的条形图生成甘特图.
我在图表中使用了3个系列.
当我单击任何一个系列生成图表后,它应该提供该系列的信息.
为此,我需要在单击后获得系列名称.
有没有办法获得我点击的系列名称和图表名称.
I am generating Gantt chart using MS chart stacked bar chart.
I am using 3 series in the chart.
After generating the chart when I click on any of the series, it should give the information of the series.
For that I need to get the series name after clicking.
Is there any way to get the series name and chartarea name which I clicked.
推荐答案
我尝试了一下,得到了如下答案
我们需要使用Mouseclick evnet,而不仅仅是clickevnet.
示例:在下面的示例中,我们将获得在clkdGraphSeries中单击的系列名称
受保护的朋友子ProdChart_Click(ByVal发送者为System.Object,ByVal e为MouseEventArgs)处理ProdChart.MouseClick
昏暗的clkdGraphPoint为整数=什么都没有
昏暗的clkdGraphSeries为字符串= Nothing
Dim clkdGraphChartArea As String = Nothing
试试
结果为DataVisualization.Charting.HitTestResult = ProdChart.HitTest(e.X,e.Y)
clkdGraphPoint = result.PointIndex
如果(clkdGraphPoint< 0)那么
App.MsgBox(单击绘制的图",MsgBoxStyle.Information)
退出子
如果结束
clkdGraphSeries = result.Series.Name
clkdGraphChartArea = result.ChartArea.Name
异常捕获
App.ErrorAdd(Me,ex.Message)
结束尝试
结束子
以同样的热情,您可以获得图表的所有属性.
I tried myself and got the answer as below
We need to use Mouseclick evnet not the just clickevnet.
Example: In below example we will get series name which is clicked in clkdGraphSeries
Protected Friend Sub ProdChart_Click(ByVal sender As System.Object, ByVal e As MouseEventArgs) Handles ProdChart.MouseClick
Dim clkdGraphPoint As Integer = Nothing
Dim clkdGraphSeries As String = Nothing
Dim clkdGraphChartArea As String = Nothing
Try
Dim result As DataVisualization.Charting.HitTestResult = ProdChart.HitTest(e.X, e.Y)
clkdGraphPoint = result.PointIndex
If (clkdGraphPoint < 0) Then
App.MsgBox("Click on the drawn graph", MsgBoxStyle.Information)
Exit Sub
End If
clkdGraphSeries = result.Series.Name
clkdGraphChartArea = result.ChartArea.Name
Catch ex As Exception
App.ErrorAdd(Me,ex.Message)
End Try
End Sub
In the same passion you can get all the properties of the graph.
这篇关于单击图表时如何获得图表的系列名称,图表名称的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文