Search code examples
activexteechart

Teechart Bar Chart SIngle Bar Pattern


How can we Provide pattern only to a single Bar of the Series.Say Suppose my Series has 4 Bars On click on a Bar it pattern should be change. I know the functionality of changing Color of a Particular Point.


Solution

  • You could store the patterns in an array and set them at the OnGetSeriesBarStyle event. Here you have an example:

    Dim myPatterns() As Integer
    
    Private Sub Form_Load()      
      TChart1.AddSeries scBar
      TChart1.Series(0).FillSampleValues
    
      ReDim myPatterns(TChart1.Series(0).Count)
      Dim i As Integer
      For i = LBound(myPatterns) To UBound(myPatterns)
        myPatterns(i) = 0
      Next i
    End Sub
    
    
    Private Sub TChart1_OnClickSeries(ByVal SeriesIndex As Long, ByVal ValueIndex As Long, ByVal Button As TeeChart.EMouseButton, ByVal Shift As TeeChart.EShiftState, ByVal X As Long, ByVal Y As Long)
      If SeriesIndex > -1 And ValueIndex > -1 Then
        myPatterns(ValueIndex) = (myPatterns(ValueIndex) + 1) Mod 20
      End If
    
      TChart1.Repaint
    End Sub
    
    Private Sub TChart1_OnGetSeriesBarStyle(ByVal SeriesIndex As Long, ByVal ValueIndex As Long, BarStyle As TeeChart.EBarStyle)
      If SeriesIndex > -1 And ValueIndex > -1 Then
        TChart1.Series(SeriesIndex).asBar.BarBrush.ClearImage
        TChart1.Series(SeriesIndex).asBar.BarBrush.Style = myPatterns(ValueIndex)
      End If
    End Sub