Area Chart - 0 Origin

TeeChart for ActiveX, COM and ASP
Post Reply
paligap
Newbie
Newbie
Posts: 19
Joined: Tue Feb 24, 2004 5:00 am
Location: Australia

Area Chart - 0 Origin

Post by paligap » Wed Aug 23, 2006 11:53 pm

Hello,

I would like to generate an area chart with origin at 0, this is possible however I would like the "fill" colour to be different for fill above the origin and below the origin.

How can I do this?

Kind Regards
Anthony

Narcís
Site Admin
Site Admin
Posts: 14730
Joined: Mon Jun 09, 2003 4:00 am
Location: Banyoles, Catalonia
Contact:

Post by Narcís » Fri Aug 25, 2006 11:41 am

Hi Anthony,

You can do something like this:

Code: Select all

Private Sub Form_Load()
    TChart1.AddSeries scArea
    With TChart1.Series(0)
        .asArea.UseYOrigin = True
        .asArea.YOrigin = 0
        For i = -5 To 5
            If (i <= .asArea.YOrigin) Then
                .Add i, "", clTeeColor
                .PointColor(.Count - 1) = vbGreen
            Else
                .Add i, "", clTeeColor
                .PointColor(.Count - 1) = vbYellow
            End If
        Next
    End With
End Sub
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

paligap
Newbie
Newbie
Posts: 19
Joined: Tue Feb 24, 2004 5:00 am
Location: Australia

Post by paligap » Wed Sep 06, 2006 6:09 am

Hello Narcis,

Thanks for your response above.

I have tried to implement your suggestion however it does not have the desired effect. I did however get the following to work, remember that the data is being sourced from a User Defined Type (array).

Within this loop, I can perform a check to see if the value is above or below the chart origin (0) however the colors are not properly cropped above and below the origin line.

Code:
For i = 1 To UBound(arrRS())
Chart_Main.Series(1).AddXY i, arrRS(i).Amount, arrRS(i).Date, clTeeColor
If arrRS(i).Amount>= 0 Then
Chart_Main.Series(1).PointColor(Chart_Main.Series(1).Count - 1) = vbGreen
Else
Chart_Main.Series(1).PointColor(Chart_Main.Series(1).Count - 1) = vbRed
End If
Next

This code will correctly color the areas above and below the origin in Green and Red however where the area changes from below the origin to above the origin, the area which is still in the negative becomes colored green.

Can we make the color change occur only when the area moves above the origin?

Regards
Anthony

Narcís
Site Admin
Site Admin
Posts: 14730
Joined: Mon Jun 09, 2003 4:00 am
Location: Banyoles, Catalonia
Contact:

Post by Narcís » Wed Sep 06, 2006 11:54 am

Hi Anthony,

That's because a single area point can't have two colours. A workaround would be splitting this point in 2 points as shown here:

Code: Select all

Private Sub Form_Load()
    Dim XVal, YVal, Offset As Double
    Dim ColorVal As OLE_COLOR
   
    Offset = 0.5
    TChart1.AddSeries scArea
   
    With TChart1.Series(0)
        .asArea.UseYOrigin = True
        .asArea.YOrigin = 0
       
        For i = -5 To 5
            XVal = XVal + 1
            YVal = i + Offset
               
            If ((YVal - 1 < .asArea.YOrigin) And (YVal > .asArea.YOrigin)) Then
                .AddXY XVal - Offset, YVal - Offset, "", clTeeColor
                .PointColor(.Count - 1) = vbGreen
            End If
            
            If (i < .asArea.YOrigin) Then
                ColorVal = vbGreen
            Else
                ColorVal = vbYellow
            End If
           
            .AddXY XVal, YVal, "", clTeeColor
            .PointColor(.Count - 1) = ColorVal
        Next
    End With
    
End Sub
Anyway, I'll add this feature to our wish-list to be considered for inclusion in future releases.
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

Post Reply