Page 1 of 1

1 bar color only... again

Posted: Mon Dec 18, 2006 2:48 pm
by 9523817
hi, I've tried to colorize only one bar.
Reading the other thread, I've understand that I must user the OnGetSeriesBarStyle . I don't think tha this is the most beautiful thing of the world.. but I can modify my code to work in this way, so, no problem.
But anyway, the snippet in the other post, doesn't work for me.

I've tried to re-build the code. In a form with a tchart control this is the what I've write

Private Sub Form_Load()
T.RemoveAllSeries
T.AddSeries scBar
T.Series(0).Add 7, "sdopf", vbRed
T.Series(0).Add 12, "sdfasdf", vbRed

T.AddSeries scBar
T.Series(1).Add 9, "asdew", vbYellow
T.Series(1).Add 10, "vdfg", vbYellow

End Sub



Private Sub T_OnGetSeriesBarStyle(ByVal SeriesIndex As Long, ByVal ValueIndex As Long, BarStyle As TeeChart.EBarStyle)

If SeriesIndex = 0 Then
If ValueIndex = 0 Then
T.Series(0).asBar.BarBrush.Style = bsCross
Else
T.Series(0).asBar.BarBrush.Style = bsSolid
End If
End If
End Sub

Private Sub T_OnGetSeriesMark(ByVal SeriesIndex As Long, ByVal ValueIndex As Long, MarkText As String)
MarkText = "S" & SeriesIndex & " V" & ValueIndex
End Sub



In this way, I make evidence into the makrs the series index and the value index (I suppose) .
In the example I want to "hide" the first value of the first serie... but...
The bar that vanish is the second! (as make serie =0, value = 1).

What goes wrong? Thanks..


p.s. I've the latest version of tchart (1.0.1.3)

Posted: Mon Dec 18, 2006 3:09 pm
by narcis
Hi BdMan,

In your example, brush has already been set for the first point (ValueIndex=0) and the OnGetSeriesBarStyle event sets the brush style for the next point to be drawn (ValueIndex=1). To achieve what you request you should do this:

Code: Select all

Private Sub Form_Load()
    T.RemoveAllSeries
    T.AddSeries scBar
    T.Series(0).Add 7, "sdopf", vbRed
    T.Series(0).Add 12, "sdfasdf", vbRed
    T.Series(0).asBar.BarBrush.Style = bsCross
    
    T.AddSeries scBar
    T.Series(1).Add 9, "asdew", vbYellow
    T.Series(1).Add 10, "vdfg", vbYellow
End Sub

Private Sub T_OnGetSeriesBarStyle(ByVal SeriesIndex As Long, ByVal ValueIndex As Long, BarStyle As TeeChart.EBarStyle)

    If SeriesIndex = 0 Then
        If ValueIndex = 0 Then
            T.Series(0).asBar.BarBrush.Style = bsSolid
'        Else
'            T.Series(0).asBar.BarBrush.Style = bsSolid
        End If
    End If
End Sub

Private Sub T_OnGetSeriesMark(ByVal SeriesIndex As Long, ByVal ValueIndex As Long, MarkText As String)
    MarkText = "S" & SeriesIndex & " V" & ValueIndex
End Sub

Posted: Mon Dec 18, 2006 3:40 pm
by 9523817
thanks a lot for the quick answer.
but...

in this way, there is something that for me doesn't work.
I've tried the modification and all seems to be fine.
But suppose that I want to modify a "group" of bars, in the example, the first (s0v0, s1v0) want be solid, and the second group (s0v1, s1v1 ) crossed.
I've modified the code of Form_Load

T.RemoveAllSeries
T.AddSeries scBar
T.Series(0).Add 7, "sdopf", vbRed
T.Series(0).Add 12, "sdfasdf", vbRed
T.Series(0).asBar.BarBrush.Style = bsDiagCross

T.AddSeries scBar
T.Series(1).Add 9, "asdew", vbYellow
T.Series(1).Add 10, "vdfg", vbYellow
T.Series(1).asBar.BarBrush.Style = bsDiagCross

and OnGetSeriesBarStyle in this way:
If ValueIndex = 1 Then
T.Series(SeriesIndex).asBar.BarBrush.Style = bsSolid
End If

The problem is that now, all bars will be crossed... not only the second.
And more.. if I make a call to tchart1.repaint, both will be solid (for what strange reason, I don't know....)

Thaks again!



narcis wrote:Hi BdMan,

In your example, brush has already been set for the first point (ValueIndex=0) and the OnGetSeriesBarStyle event sets the brush style for the next point to be drawn (ValueIndex=1). To achieve what you request you should do this:

Code: Select all

Private Sub Form_Load()
    T.RemoveAllSeries
    T.AddSeries scBar
    T.Series(0).Add 7, "sdopf", vbRed
    T.Series(0).Add 12, "sdfasdf", vbRed
    T.Series(0).asBar.BarBrush.Style = bsCross
    
    T.AddSeries scBar
    T.Series(1).Add 9, "asdew", vbYellow
    T.Series(1).Add 10, "vdfg", vbYellow
End Sub

Private Sub T_OnGetSeriesBarStyle(ByVal SeriesIndex As Long, ByVal ValueIndex As Long, BarStyle As TeeChart.EBarStyle)

    If SeriesIndex = 0 Then
        If ValueIndex = 0 Then
            T.Series(0).asBar.BarBrush.Style = bsSolid
'        Else
'            T.Series(0).asBar.BarBrush.Style = bsSolid
        End If
    End If
End Sub

Private Sub T_OnGetSeriesMark(ByVal SeriesIndex As Long, ByVal ValueIndex As Long, MarkText As String)
    MarkText = "S" & SeriesIndex & " V" & ValueIndex
End Sub

Posted: Wed Dec 27, 2006 11:17 am
by Pep
Hi,

in that case, you can do :

Code: Select all

Private Sub Form_Load()
T.RemoveAllSeries
T.AddSeries scBar
T.Series(0).Add 7, "sdopf", vbRed
T.Series(0).Add 12, "sdfasdf", vbRed
'T.Series(0).asBar.BarBrush.Style = bsDiagCross

T.AddSeries scBar
T.Series(1).Add 9, "asdew", vbYellow
T.Series(1).Add 10, "vdfg", vbYellow
'T.Series(1).asBar.BarBrush.Style = bsDiagCross
End Sub

Private Sub T_OnGetSeriesBarStyle(ByVal SeriesIndex As Long, ByVal ValueIndex As Long, BarStyle As TeeChart.EBarStyle)
If ValueIndex = 1 Then
T.Series(SeriesIndex).asBar.BarBrush.Style = bsSolid
Else
T.Series(SeriesIndex).asBar.BarBrush.Style = bsDiagCross
End If
End Sub

ahi ahi....

Posted: Tue Jan 09, 2007 7:58 pm
by 9523817
excuseme... i'm know that i'm boring...
but it doesn't work in the way that i want.

I would like maker something like the above code... I would have an array of bars that must be "crossed". This array must be dynamic.
In this array I set the bars (serie and index) to disable.
I could even set (if it possible) the "crossed" in the creation of chart (initSeries), but I don't understand how!!!
(emh.. for explanation, I put the marks explained as series/index, and in the array I put the positions that i want to "cross")

Please, if someone could help me.. this thing make me crazy... and more seriously, my work is stop!!!!!!!
(but why, simply, TChart1_OnGetSeriesBarStyle could not works "before" draw the style ?????????)

thank thanks a lot!

p.s. put a chart (tchart1) in a form to reproduce the code

Option Explicit

Private Type tp_todisable
serie As Long
value As Long
End Type
Private arrToDisable() As tp_todisable





Private Sub initSeries()
TChart1.RemoveAllSeries

Dim lngSerie
Dim lngC As Long

lngSerie = TChart1.AddSeries(scBar)
TChart1.Series(lngSerie).Color = vbRed
TChart1.Series(lngSerie).Title = "Ita"
TChart1.Series(lngSerie).Add Rnd(100), "2001 M", vbRed
TChart1.Series(lngSerie).Add Rnd(100), "2002 M", vbRed
TChart1.Series(lngSerie).Add Rnd(100), "2001 F", vbRed
TChart1.Series(lngSerie).Add Rnd(100), "2002 F", vbRed
' TChart1.Series(lngSerie).asBar.BarBrush.Style = bsBackDiagSmall
TChart1.Series(lngSerie).Marks.Style = smsValue


lngSerie = TChart1.AddSeries(scBar)
TChart1.Series(lngSerie).Color = vbGreen
TChart1.Series(lngSerie).Title = "Ue"
TChart1.Series(lngSerie).Add Rnd(100), "2001 M", vbGreen
TChart1.Series(lngSerie).Add Rnd(100), "2002 M", vbGreen
TChart1.Series(lngSerie).Add Rnd(100), "2001 F", vbGreen
TChart1.Series(lngSerie).Add Rnd(100), "2002 F", vbGreen
' TChart1.Series(lngSerie).asBar.BarBrush.Style = bsBackDiagSmall
TChart1.Series(lngSerie).Marks.Style = smsValue


lngSerie = TChart1.AddSeries(scBar)
TChart1.Series(lngSerie).Color = vbYellow
TChart1.Series(lngSerie).Title = "xUe"
TChart1.Series(lngSerie).Add Rnd(100), "2001 M", vbYellow
TChart1.Series(lngSerie).Add Rnd(100), "2002 M", vbYellow
TChart1.Series(lngSerie).Add Rnd(100), "2001 F", vbYellow
TChart1.Series(lngSerie).Add Rnd(100), "2002 F", vbYellow
' TChart1.Series(lngSerie).asBar.BarBrush.Style = bsBackDiagSmall
TChart1.Series(lngSerie).Marks.Style = smsValue
End Sub
Private Sub disableSeriesBar()
Dim intC As Integer

intC = 0
ReDim arrToDisable(0 To 0)


intC = intC + 1
ReDim Preserve arrToDisable(0 To intC)
arrToDisable(intC).serie = 0
arrToDisable(intC).value = 1


intC = intC + 1
ReDim Preserve arrToDisable(0 To intC)
arrToDisable(intC).serie = 1
arrToDisable(intC).value = 0


intC = intC + 1
ReDim Preserve arrToDisable(0 To intC)
arrToDisable(intC).serie = 2
arrToDisable(intC).value = 0

End Sub

Private Sub Form_Load()
'init chart
TChart1.Aspect.View3D = False

'init series and their values
initSeries

'init the bars to disbale (with bsBackDiagSmall as "color")
disableSeriesBar

End Sub








Private Sub TChart1_OnGetSeriesBarStyle(ByVal SeriesIndex As Long, ByVal ValueIndex As Long, BarStyle As TeeChart.EBarStyle)

Dim i As Long
Dim bFound As Boolean

Dim lngSerie2Check As Long
Dim lngValueIndex2Check As Long


'00 -- set the series&valuesindex to compare: rember that
' the changes made in OnGetSeriesBarStyle envolve the next bar!!
If ValueIndex = TChart1.Series(SeriesIndex).Count - 1 Then
lngSerie2Check = SeriesIndex + 1
lngValueIndex2Check = 0
Else
lngSerie2Check = SeriesIndex
lngValueIndex2Check = ValueIndex + 1
End If

'00 -- search if the values of serie/value found are in array of bars
' to disabling
bFound = False
For i = 0 To UBound(arrToDisable)
If (arrToDisable(i).serie = lngSerie2Check) And _
(arrToDisable(i).value = lngValueIndex2Check) Then
bFound = True
Exit For
End If
Next i


'01 -- set the style according to the bFound
If bFound Then
Debug.Print "set for next of " & SeriesIndex & "/" & ValueIndex & ": (" & _
lngValueIndex2Check & "/" & lngValueIndex2Check & ") diagonal"
TChart1.Series(SeriesIndex).asBar.BarBrush.Style = bsBackDiagSmall
Else
Debug.Print "set for next of " & SeriesIndex & "/" & ValueIndex & ": (" & _
lngValueIndex2Check & "/" & lngValueIndex2Check & ") solid "
TChart1.Series(SeriesIndex).asBar.BarBrush.Style = bsSolid
End If



End Sub

Private Sub TChart1_OnGetSeriesMark(ByVal SeriesIndex As Long, ByVal ValueIndex As Long, MarkText As String)
'only to explain series and valueindx
MarkText = "[" & SeriesIndex & "/" & ValueIndex & "]"
End Sub

Posted: Tue Jan 16, 2007 1:40 am
by Pep
Hi,

I'm able to see the problem here. We're investigating which could be the problem and trying to find a possible workaround. I'll back with resulls as soon as possible.

thanks

Posted: Mon Jan 22, 2007 8:56 am
by 9523817
First of all, thank for support.
And after.. there are some news?? The problem grows evryday, for me :0)

Posted: Tue Jan 30, 2007 5:15 pm
by Pep
Hi,

sorry for delay !

we've been investigating about this problem, and the results are that different brushes for the same Series is not yet supported through the OnGetSeriesBarStyle, for the moment only different colors can be assigned.

But there's another way to accomplish it. It's by drawing manually the Bars (using the OnAfterDraw event). Please check the following code :

Code: Select all

Private Sub TChart1_OnAfterDraw()

Dim SeriesIndex
Dim ValueIndex
Dim barWidth
Dim bFound
Dim left, top, right, bottom
Dim lngSerie2Check As Long
Dim lngValueIndex2Check As Long
Dim i As Long
    
For SeriesIndex = 0 To TChart1.SeriesCount - 1
  For ValueIndex = 0 To TChart1.Series(SeriesIndex).Count - 1

   '00 -- set the series&valuesindex to compare: rember that
    ' the changes made in OnGetSeriesBarStyle envolve the next bar!!
    If ValueIndex = TChart1.Series(SeriesIndex).Count - 1 Then
        lngSerie2Check = SeriesIndex + 1
        lngValueIndex2Check = 0
    Else
        lngSerie2Check = SeriesIndex
        lngValueIndex2Check = ValueIndex + 1
    End If
        
    '00 -- search if the values of serie/value found are in array of bars
    ' to disabling
      
    bFound = False
        
    For i = 0 To UBound(arrToDisable)
        If (arrToDisable(i).serie = lngSerie2Check) And _
          (arrToDisable(i).value = lngValueIndex2Check) Then
          bFound = True
          Exit For
        End If
    Next i
    
    barWidth = TChart1.Series(SeriesIndex).asBar.barWidth
    
    With TChart1.Canvas
      If bFound Then
         left = TChart1.Series(SeriesIndex).CalcXPos(ValueIndex)
         top = TChart1.Series(SeriesIndex).CalcYPos(ValueIndex)
         right = TChart1.Series(SeriesIndex).CalcXPos(ValueIndex) + (barWidth + 1)
         bottom = TChart1.Axis.bottom.Position
        .Brush.Style = bsBackDiagSmall
        .BackColor = TChart1.Series(SeriesIndex).PointColor(ValueIndex)
        .Rectangle left, top, right, bottom
      Else
        .Brush.Style = bsSolid
        
      End If
    End With

  Next ValueIndex
Next SeriesIndex

End Sub