Hi
I am using Ultrachart to generate a column chart.
I need to set Y axis minimum range as 20% less than the minimum value and Maximum Range as 20% more than the maximum value in the data set.
My current code generates column chart by setting Y axis numbers automatically. Please let me know how to do this. Thanks.
Me.UltraChart1.DataSource = DS
Me.UltraChart1.DataBind()
UltraChart1.Data.SwapRowsAndColumns = True
UltraChart1.TitleLeft.Text = Me.cmbMeasure.Text
UltraChart1.TitleLeft.Visible = True
UltraChart1.TitleLeft.HorizontalAlign = StringAlignment.Center
UltraChart1.ColumnChart.ColumnSpacing = 1
Me.txtChartLabel.Text = Me.cmbMeasure.Text & " Trend"
Me.UltraChart1.Axis.X.Labels.ItemFormatString = "<ITEM_LABEL:MM/dd/yy>"
Me.UltraChart1.Axis.Y.Labels.FontColor = Color.Black
Me.UltraChart1.Axis.X.Labels.FontColor = Color.Black
Me.UltraChart1.TitleBottom.Text = "Week Ending"
UltraChart1.TitleBottom.HorizontalAlign = StringAlignment.Center
UltraChart1.TitleBottom.Visible = True
UltraChart1.Axis.X.Labels.SeriesLabels.Visible = False
UltraChart1.Axis.Y.Labels.SeriesLabels.Visible = False
Dim myTable As DataTable
myTable = DS.Tables(0)
'First Include Additional column
For i = 0 To myTable.Columns.Count - 1
If myTable.Columns(i).ColumnName = Me.cmbMeasure.Text Then
UltraChart1.Data.IncludeColumn(i, True)
If InStr(myTable.Columns(i).ColumnName, "$") > 0 Then
Me.UltraChart1.Axis.Y.Labels.ItemFormatString = "<DATA_VALUE:$##,###,###>"
ElseIf InStr(myTable.Columns(i).ColumnName, "%") > 0 Then Me.UltraChart1.Axis.Y.Labels.ItemFormatString = "<DATA_VALUE:#0.#0>%"
Else
Me.UltraChart1.Axis.Y.Labels.ItemFormatString = "<DATA_VALUE:##,###,###>"
End If
Next
Me.UltraChart1.ColumnChart.ChartText.Item(0).VerticalAlign = StringAlignment.Far
Above code is generating column chart with automatically setting numbers on Y axis.
I added following code to set Minimum and maximum range. But its generating overflow exception. Following method is called till overflow exception is generated.
Private Sub UltraChart1_FillSceneGraph(ByVal sender As Object, ByVal e As Infragistics.UltraChart.Shared.Events.FillSceneGraphEventArgs) Handles UltraChart1.FillSceneGraph
Dim MinValue, MaxValue As Integer
Dim yAxis As Infragistics.UltraChart.Core.IAdvanceAxis
yAxis = e.Grid("Y")
If Not IsNothing(yAxis) Then
MinValue = yAxis.Minimum
MaxValue = yAxis.Maximum
MinValue = Math.Round(MinValue * 0.8)
MaxValue = Math.Round(MaxValue * 1.2)
Me.UltraChart1.Axis.Y.RangeMin = MinValue
Me.UltraChart1.Axis.Y.RangeMax = MaxValue
Me.UltraChart1.Axis.Y.RangeType = Infragistics.UltraChart.Shared.Styles.AxisRangeType.Custom
End Sub
The exception happens because you are setting properties on the chart control through the UltraChart1 reference. Any changes wll try to redraw the chart and FillSceneGraph will be raised again, creating an infinite cycle.
Instead of setting range properties inside FillSceneGraph, set Minimum and Maximum properties on the axis directly:yAxis.Minimum = MinValueyAxis.Maximum = MaxValue
I'm not sure if spw managed to get this to work, but I haven't. I'm not getting any errors though, it just simply isn't moving the y axis down. My minimum value is 700 and it should be dropping it to 665 but it isn't. Here is my code:
Private Sub Chart_FillSceneGraph(ByVal sender As Object, ByVal e As Infragistics.UltraChart.Shared.Events.FillSceneGraphEventArgs) Handles Chart.FillSceneGraph Dim minValue As Double Dim yAxis As Infragistics.UltraChart.Core.IAdvanceAxis ' Obtain the Y Axis of the chart. yAxis = e.Grid("Y")
' Lower the y axis by 5%. If Not yAxis Is Nothing Then minValue = yAxis.Minimum
minValue = minValue - Math.Round(minValue * 0.05)
yAxis.RangeType = Infragistics.UltraChart.Shared.Styles.AxisRangeType.Custom
yAxis.RangeMin = minValue End If End Sub
What am I doing wrong?
That's exactly what I did. I ended up taking it out of FillSceneGraph and putting it where my data was retrieved (before the series were being added to the chart but after the data was obtained/generated). The stored procedure returning the data also now returns the min data value across all points so I am using that value to set as the RangeMin and it appears as though the RangeMax also needs to be set in order for this to work properly so I will also have my stored procedure return the max data value as well and do the same thing.
Thanks! :)
It appears that I was mistaken and setting MinValue and MaxValue will not have an effect on the chart. I should have suggested a different approach to this, and it is one that doesn't involve using FillSceneGraph, as most of its event args are meant for retrieving values instead of setting them.
You should loop through your datasource and manually calculate the min and max values, then set RangeMin and RangeMax plus the 5% margin.