2012-08-29 34 views
0

目前,我有叫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 

..但它所做的只是最後一堆酒吧的工作。我需要一些適用於所有酒吧的東西。

請幫忙。

+0

看看下面... http://stackoverflow.com/questions/11316319/finding-series-item-clicked-in-a-chart-in-vb-2008/11317283 #11317283 – APrough

回答

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 
0

你應該嘗試使用被點擊的方法:

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事件做的工作更合適。如果這沒有幫助,請不要猶豫,讓我知道。