VB.net 重绘/刷新/重新计算图表

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/18919833/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-17 15:09:31  来源:igfitidea点击:

VB.net Redraw / Refresh / recalculate Chart

vb.netchartsdiagram

提问by gubbfett

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.

就我而言,我有一个每 X 分钟更新一次的图表。当程序启动时,它会在文件中查找某些值。假设只有一个值(在这种情况下为一列),并且该值是 20。然后它显示它很好,最大值为 30。

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"?

在这种情况下,我们说现在的值是 60,然后 y 轴仍然在 30 作为最大值,所以我看不到列的末端(顶部)。我如何告诉图表/图表区域“像第一次渲染一样重新绘制自己”?

采纳答案by Stefan Orie

Have you tried auto-scaling the y-axis?

您是否尝试过自动缩放 y 轴?

' 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.

您应该在每次图表刷新时设置这些值,然后轴应该自动调整。

回答by Norcel

To reset the auto scale just use this after loading the points into the chart.

要重置自动缩放,只需在将点加载到图表后使用它。

Chart1.ResetAutoValues()

回答by Carlos Borau

Available since .NET 4.0: Chart1.ChartAreas[0].RecalculateAxesScale();

自 .NET 4.0 起可用: Chart1.ChartAreas[0].RecalculateAxesScale();