Page 1 of 1
Area Chart - 0 Origin
Posted: Wed Aug 23, 2006 11:53 pm
by 9080944
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
Posted: Fri Aug 25, 2006 11:41 am
by narcis
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
Posted: Wed Sep 06, 2006 6:09 am
by 9080944
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
Posted: Wed Sep 06, 2006 11:54 am
by narcis
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.