当标签为 0 - vb.net 时,不在 windows 表单图表中显示标签

Do not show a label in windows form chart when that label is 0 - vb.net

我有一个包含饼图的 windows 表单(使用图表控件)。 此图表中有 5 个数据点,使用 5 个数字上下框输入。 我有一个代码可以绘制饼图并显示标签。但是,当数据点的值为 0 时,图表会显示“0”标签。我不想那样,我想隐藏值为 0 的特定标签,只显示那些值为不为 0 的标签。 我该怎么做呢?我尝试使用图表属性但没有找到任何东西。我还尝试了以下代码,但效果不佳:

For Each dp As DataPoint In Chart1.Series("Series1").Points
  If dp.YValues(0) <> 0 Then
      dp.IsValueShownAsLabel = True
  End If
Next

检查了 IsValueShownAsLabel 的图表属性。它设置为 "False"。数据来自使用 Chart1.Series("Series1").Points.AddY(NumericUpDown1.Value) Chart1.Series("Series1").Points.AddY(NumericUpDown2.Value) Chart1.Series("Series1").Points.AddY(NumericUpDown3.Value) Chart1.Series("Series1").Points.AddY(NumericUpDown4.Value) Chart1.Series("Series1").Points.AddY(NumericUpDown5.Value)

形式的 numericupdown 框

有 5 个数据点来自 5 个 numericupdown 框。

此外,这里有一个显示图表的 image。图表中看到的 0.0% 是我不想要的东西。的数据点设置为 0,但它仍然显示。

感谢任何帮助。 谢谢。

不显示不为零的标签,而是隐藏为零的标签:

For Each dp As DataPoint In Chart1.Series("Series1").Points
  If dp.YValues(0) = 0 Then
      dp.IsValueShownAsLabel = False
  End If
Next

这很简单,适用于所有人:

For Each dp As DataPoint In Chart1.Series("Series1").Points
        If dp.YValues(0) = 0 Then
            dp.IsEmpty = True
        Else
            'Show label as "Y Value as Percent of Total" with format as % and precision 1.
            Chart1.Series("Series1").Label = "#VAL{N1}%"
        End If
    Next