Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
165
Ultra chart setting Minimum and maximum value for Y axis
posted

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

                        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 If

    End Sub

 

Parents
  • 26458
    Suggested Answer
    Offline posted

    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 = MinValue
    yAxis.Maximum = MaxValue

Reply Children