Search code examples
vb.netchartsdiagram

VB.net Redraw / Refresh / recalculate Chart


I guess there's tons of answers, but i have only found answers regarding the data update, not the chart itself.

In my case i have a chart that updates every X minutes. When the program starts, it looks in a file for some values. Lets say there's only one one value (one column in this case), and this value is 20. Then it shows it nice with 30 as maximum.

When it refresh, i do something like this

TheDiagram.Series.Clear()
Dim Serie_Value As New Series
With Serie_Value
    .Name = "MySerie"
    .ChartType = SeriesChartType.StackedColumn
    .Color = Color.Green
    With .Points
        .AddXY("MyName", theValueFromFile)
    End With
End With
TheDiagram.Series.Add(Serie_Value)

In this case, we say that the value now is 60, then the y-axis is still on 30 as max so that I can't see the end (top) of the column. How can I tell the chart/chartarea to "redraw yourself like you were rendered the first time"?


Solution

  • Have you tried auto-scaling the y-axis?

    ' Auto axis scale
    Chart1.ChartAreas("ChartArea1").AxisY.Minimum = [Double].NaN
    Chart1.ChartAreas("ChartArea1").AxisY.Maximum = [Double].NaN
    

    You should set those every time the chart refreshes, the axis should adjust automatically then.