vb.net 仅当不等于零时才显示堆积柱形图标签值?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/13617583/
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 11:22:21  来源:igfitidea点击:

Show stacking column chart label value only if not equal to zero?

vb.netcharts

提问by JanT

I have following code, original code is: here

我有以下代码,原始代码是:here

Public Class Form1
    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Dim dtTest As DataTable = New DataTable
        dtTest.Columns.Add("col1", GetType(Integer))
        dtTest.Columns.Add("col2", GetType(Integer))
        dtTest.Columns.Add("col3", GetType(String))

        dtTest.Rows.Add(0, 1, "S")
        dtTest.Rows.Add(0, 1, "H")
        dtTest.Rows.Add(80, 1, "C")
        dtTest.Rows.Add(43, 2, "S")
        dtTest.Rows.Add(11, 2, "H")
        dtTest.Rows.Add(55, 2, "C")
        dtTest.Rows.Add(30, 3, "S")
        dtTest.Rows.Add(85, 3, "H")
        dtTest.Rows.Add(53, 3, "C")
        dtTest.Rows.Add(55, 4, "S")
        dtTest.Rows.Add(55, 4, "H")
        dtTest.Rows.Add(11, 4, "C")

        Dim dv As DataView = New DataView(dtTest)
        dv.Sort = "col2 asc"

        Chart1.Series.RemoveAt(0) 'this is just to remove the default Series in a 
        'VB.NET chart; you may not need this

        Chart1.DataBindCrossTable(dv, "col3", "col2", "col1", "Label=col1")

        For Each cs As Series In Chart1.Series
            cs.ChartType = SeriesChartType.StackedColumn
        Next

    End Sub
End Class

Code generates chart below.. What I want to know if there is a way not to display a value on column if it is zero, like shown on left most column OR total value on the top of the column would be also good. I found how to do that in excel but did not manage to achieve for this program.

代码生成下面的图表.. 我想知道是否有一种方法可以在列上显示值为零时不显示值,例如显示在最左侧的列或列顶部的总值也很好。我在 excel 中找到了如何做到这一点,但没有设法实现这个程序。

Thanks a lot for help

非常感谢帮助

Result

结果

采纳答案by Mark Hall

You will need to setup Filteringfor your Series, I was able to get the result you were looking for by using the Filter(CompareMethod,Double,Series), along with DataManipulator.FilterSetEmptyPointsand DataManipulator.FilterMatchPointsProperties.

您需要为您的系列设置过滤,我能够通过使用Filter(CompareMethod,Double,Series)以及DataManipulator.FilterSetEmptyPointsDataManipulator.FilterMatchPoints属性来获得您正在寻找的结果。

Modified Code

修改代码

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    Dim dtTest As DataTable = New DataTable
    dtTest.Columns.Add("col1", GetType(Integer))
    dtTest.Columns.Add("col2", GetType(Integer))
    dtTest.Columns.Add("col3", GetType(String))

    dtTest.Rows.Add(0, 1, "S")
    dtTest.Rows.Add(0, 1, "H")
    dtTest.Rows.Add(80, 1, "C")
    dtTest.Rows.Add(43, 2, "S")
    dtTest.Rows.Add(11, 2, "H")
    dtTest.Rows.Add(55, 2, "C")
    dtTest.Rows.Add(30, 3, "S")
    dtTest.Rows.Add(85, 3, "H")
    dtTest.Rows.Add(53, 3, "C")
    dtTest.Rows.Add(55, 4, "S")
    dtTest.Rows.Add(55, 4, "H")
    dtTest.Rows.Add(11, 4, "C")

    Dim dv As DataView = New DataView(dtTest)
    dv.Sort = "col2 asc"

    Chart1.Series.RemoveAt(0) 'this is just to remove the default Series in a 
    'VB.NET chart; you may not need this
    Chart1.DataManipulator.FilterSetEmptyPoints = True 'Points that match filter will be marked as empty
    Chart1.DataManipulator.FilterMatchedPoints = True  'Filter points that match Filter criteria



    Chart1.DataBindCrossTable(dv, "col3", "col2", "col1", "Label=col1")

    For Each cs As Series In Chart1.Series
        Chart1.DataManipulator.Filter(DataVisualization.Charting.CompareMethod.EqualTo, 0, cs)   'Compare if equal to zero
        cs.ChartType = SeriesChartType.StackedColumn
        Dim dpcp As DataPointCustomProperties = New DataPointCustomProperties

    Next

End Sub

Result

结果

enter image description here

在此处输入图片说明