Hi, I am trying to have the minimum value on the Y-Axis as a negative value and make it the start of every column in a ColumnChart.
As example, I have, let's say, 5 values: (1,10); (2,15); (3,0); (4,-10); (5,-5). And I set the minimum value as -20 for example.
I want the chart to show me a bar that goes from
-20 to 10 for the first value; -20 to 15, for the 2nd; -20 to 0, -20 to -10 and -20 to -5.
It will be as if I had the -20 as the zero-base. I don't want the negative values to go downards and the positive upwards. Everything goes upwards starting at the value set.
Any ideas on how to achieve this?
Thanks,
Imad
Hi Petia,
thanks a lot for your help. I had to change some of your code since the 0-line might actually be in the positive or in the negative.
But your code did put me on the right track.
Here is the code that worked for me:
Dim xAxis As Infragistics.UltraChart.Core.IAdvanceAxis = Nothing
Dim b As Infragistics.UltraChart.Core.Primitives.Box
Dim zeroY As Single = 0
Dim fromStartToZero As Single = 0
Dim startPoint As Single = 0
xAxis = DirectCast(e.Grid("X"), Infragistics.UltraChart.Core.IAdvanceAxis)
For i As Integer = 0 To e.SceneGraph.Count - 1
If TypeOf (e.SceneGraph(i)) Is Infragistics.UltraChart.Core.Primitives.Box Then
b = e.SceneGraph(i)
If b.Value Is Nothing Then Continue For
If (...) Then 'Code to get the rect.Y of an item which value is 0
zeroY = b.rect.Y
startPoint = DirectCast(xAxis, Infragistics.UltraChart.Core.Layers.Axis).startPoint.Y
fromStartToZero = startPoint - zeroY
End If
If b.Value >= 0 Then
If fromStartToZero > 0 Then
b.rect.Height += fromStartToZero
'Else 'Do nothing since it is already shrunk to show only the needed part
Else
If b.rect.Y + b.rect.Height > startPoint Then
b.rect.Height = 0
b.rect.Y += b.rect.Height ' or the same result: zeroY + b.rect.Height
b.rect.Height = fromStartToZero - b.rect.Height
Next
Thanks again.
Hi Imad,
There is not a property which you can use to achive the desired functionality.
There are two approachies you can use to achive it manually:
- change the axis labels texts, i.e. 0 become -20 etc... or
- use FillSceneGraph event handler, get every box of the chart and change its rectangle height with the difference to the x axis. For example:
void ultraChart1_FillSceneGraph(object sender, Infragistics.UltraChart.Shared.Events.FillSceneGraphEventArgs e){ IAdvanceAxis xAxis = (IAdvanceAxis)e.Grid["X"]; for (int i = 0; i < e.SceneGraph.Count; i++) { Box b = e.SceneGraph[i] as Box; if (b != null) { Rectangle currentRect = b.rect; int difference = (xAxis as Axis).startPoint.Y - currentRect.Y; currentRect.Height = currentRect.Height + difference; b.rect = currentRect; } }}
Let me know if you need further assistance.