how can i change the color of the bar/series

TeeChart for ActiveX, COM and ASP
Narcís
Site Admin
Site Admin
Posts: 14730
Joined: Mon Jun 09, 2003 4:00 am
Location: Banyoles, Catalonia
Contact:

Post by Narcís » Tue May 09, 2006 2:07 pm

Hi Aravind,

That's because you are not setting a different color for each point in the series. Try using the code below which assign a random color to each point:

Code: Select all

Private Sub Form_Load()
    Dim A(2, 2), B(2, 2), C(2)
    
    A(0, 0) = 14
    A(1, 0) = 134
    A(1, 1) = 23
    A(0, 1) = 43
    
    B(0, 0) = 2
    B(1, 0) = 23
    B(0, 1) = 24
    B(1, 1) = 43
    
    C(0) = "s"
    C(1) = "sd"
    
    TChart1.AddSeries scBar
    TChart1.AddSeries scBar
    
    For i = 0 To 1
        For j = 0 To 1
            Randomize
            TChart1.Series(i).Add A(i, j), B(i, j), RandomColor
        Next j
        TChart1.Series(i).ColorEachPoint = True
    Next i
End Sub

Private Function RandomColor() As OLE_COLOR
    RandomColor = RGB(CInt(Int((255 * Rnd()) + 1)), CInt(Int((255 * Rnd()) + 1)), CInt(Int((255 * Rnd()) + 1)))
End Function
Best Regards,
Narcís Calvet / Development & Support
Steema Software
Avinguda Montilivi 33, 17003 Girona, Catalonia
Tel: 34 972 218 797
http://www.steema.com
Image Image Image Image Image Image
Instructions - How to post in this forum

Aravind
Newbie
Newbie
Posts: 75
Joined: Fri Nov 15, 2002 12:00 am

Post by Aravind » Tue May 09, 2006 2:45 pm

Now each bar has different colors, when i try to change color through chart editor , nothing is changing (even though i set color each point to false by means of unchecking the checkbox in property page) still bar is not changed ..


My Requirement is : for each series i have to assign a color and at the run time i need to change the color of the each series ....


help me
aravind

Aravind
Newbie
Newbie
Posts: 75
Joined: Fri Nov 15, 2002 12:00 am

code

Post by Aravind » Tue May 09, 2006 2:48 pm

Dim A(2, 2), B(2, 2), C(2)
A(0, 0) = 14
A(1, 0) = 134
A(1, 1) = 23
A(0, 1) = 43
B(0, 0) = 2
B(1, 0) = 23
B(0, 1) = 24
B(1, 1) = 43

C(0) = "s"
C(1) = "sd"
TChart1.AddSeries scBar
TChart1.AddSeries scBar
For i = 0 To 1
For J = 0 To 1
TChart1.series(i).Add A(i, J), B(i, J), TChart1.series(i).Color
Next J
TChart1.series(i).ColorEachPoint = False
Next i


the above code i am able to get the series color same but at the run time when i use chart editor to change the bar color , it is not changing .... how can it be achieved (even i checked coloreachpoint check box)

aravind

Pep
Site Admin
Site Admin
Posts: 3303
Joined: Fri Nov 14, 2003 5:00 am
Contact:

Post by Pep » Mon May 15, 2006 9:22 am

Hi Aravind,

to be able to change the color of the Series at runtime (via Chart editor) you will have to assign the desired Series color using for example :
tChart1.Series(0).Color = vbblue
and assing a clTeeColor constant for each add :
TChart1.series(i).Add A(i, J), B(i, J), clTeeColor

Specifying a color in the Add means that you want to set a different color for each point, and then wont allow to change the color of the Serie in the Editor.

Post Reply