在堆积条形图中,如何找到我点击的栏?

时间:2012-08-29 13:10:23

标签: vb.net teechart

目前我的表格中有一个名为tChart的tChart控件:..

Private Sub txtChart1_Click(sender As System.Object, e As System.EventArgs) Handles txtChart1.Click


TChart1.Series.Clear()

Dim series1 As New Steema.TeeChart.Chart

Dim FirstLabel = New Label()
FirstLabel.Name = "FirstLabel.Name"
FirstLabel.Text = " FirstLabel.Text"

Dim SecondLabel = New System.Windows.Forms.Label()
Dim GridBand = New Steema.TeeChart.Tools.GridBand()

'Main bar 1
Dim BarSeries1 = New Steema.TeeChart.Styles.Bar()
BarSeries1.Brush.Color = System.Drawing.Color.FromArgb(192, 255, 48)
BarSeries1.MultiBar = Steema.TeeChart.Styles.MultiBars.Stacked
BarSeries1.Pen.Color = Color.FromArgb(48, 255, 192)
BarSeries1.Title = "barSeries1"
BarSeries1.XValues.DataMember = "X"
BarSeries1.XValues.Order = Steema.TeeChart.Styles.ValueListOrder.Ascending
BarSeries1.YValues.DataMember = "Bar"

BarSeries1.Add({123, 123, 123, 123, 123})

TChart1.Series.Add(BarSeries1)


'Main bar 2
Dim BarSeries2 = New Steema.TeeChart.Styles.Bar()
BarSeries2.Brush.Color = System.Drawing.Color.FromArgb(48, 255, 192)
BarSeries2.MultiBar = Steema.TeeChart.Styles.MultiBars.Stacked
BarSeries2.Pen.Color = Color.FromArgb(48, 255, 192)
BarSeries2.Title = "barSeries2"
BarSeries2.XValues.DataMember = "X"
BarSeries2.XValues.Order = Steema.TeeChart.Styles.ValueListOrder.Ascending
BarSeries2.YValues.DataMember = "Bar"

BarSeries2.Add({123, 123, 123, 123, 123})

TChart1.Series.Add(BarSeries2)


TChart1.Aspect.SmoothingMode = Drawing2D.SmoothingMode.HighQuality


End Sub

...在同一个表单类中我有这个事件处理程序...

Private Sub TChart1_MouseDown(sender As Object, e As System.Windows.Forms.MouseEventArgs) Handles TChart1.MouseDown
mouseX.Text = e.X
mouseY.Text = e.Y

If TChart1.Series.Count > 0 Then

Dim CollectionOfBars As New List(Of String)

For idxSeries As Integer = 0 To TChart1.Series.Count - 1
Dim srs As Steema.TeeChart.Styles.Bar = TChart1.Series(idxSeries)

If srs.BarBounds.Contains(e.X, e.Y) Then
CollectionOfBars.Add(srs.TitleOrName)
End If

Next

txtCollisions.Text = Join(CollectionOfBars.ToArray, ", ")
End If

End Sub

......但它的作用只适用于最后一叠酒吧。我需要能适用于所有酒吧的东西。

请帮忙。

2 个答案:

答案 0 :(得分:0)

您应该尝试使用Clicked方法:

If srs.Clicked(e.X, e.Y) <> -1 Then
CollectionOfBars.Add(srs.TitleOrName)
End If

而不是您使用的代码:

If srs.BarBounds.Contains(e.X, e.Y) Then
CollectionOfBars.Add(srs.TitleOrName)
End If

使用ClickSeries事件执行此任务可能更合适。如果这没有帮助,请不要犹豫,让我知道。

答案 1 :(得分:0)

Private Sub tctChartBar_Click(Sender As Object, srsBarSeriesClicked As Styles.Series, ValueIndex As Integer, e As System.Windows.Forms.MouseEventArgs) Handles tctScrollableChart.ClickSeries
    Dim strMethodAddress As String = strClassAddress & "Private Sub Bar_Click(Sender As Object, srsBarSeriesClicked As Styles.Series, ValueIndex As Integer, e As System.Windows.Forms.MouseEventArgs) Handles GetChartComponent.ClickSeries"
    Try
        Dim CAAGCanvasConversionBreakdownCriteria As clsCriteria = ctaCriteriaSetting.Copy
        CAAGCanvasConversionBreakdownCriteria.SetWeekNum(srsBarSeriesClicked(ValueIndex).Label)
        frmCAAGCanvasConversionBreakdown.RemoteLaunch(CAAGCanvasConversionBreakdownCriteria, GetSelectedCanvassGroupID)

    Catch ex As Exception
        If blnLoudExceptions Then MsgBox("General Exception Caught in Method: " & strMethodAddress)
    End Try
End Sub