vb.net中的饼图代码

时间:2015-02-15 14:53:14

标签: vb.net pie-chart

我在vb.net中将此代码用于饼图。这个工作正常,但有一个问题是,当其中一个yValue为0时,它在饼图中显示为0。

我想知道如何停止在饼图中显示0值以及我必须在代码中更正的内容,以便它不会为0值。

Dim yValues As Double() = {str_total, Totalmale.ToString, Totalfemale.ToString, Totalengagedact.ToString, Totalmaterial.ToString, Totalpattaholder.ToString} ' Getting values from Textboxes 
Dim xValues As String() = {"Total Beneficiary", "Male", "Female", "Engaged in same activity before", "Material Support received", "Patta holder"} ' Headings
                Dim seriesName As String = Nothing

                ' Note 1 : Clear chart before fill - VERY IMPORTANT and can generate exception if you are generating
                '          multiple charts in loop and have not included below lines !
                ' Note 2 : Chrt variable here is the Name of your Chart 
                Chart1.Series.Clear()
                Chart1.Titles.Clear()

                ' Give unique Series Name
                seriesName = "ChartInv"
                Chart1.Series.Add(seriesName)

                ' Bind X and Y values
               Chart1.Series(seriesName).Points.DataBindXY(xValues, yValues)

                ' Define Custom Chart Colors
                Chart1.Series(seriesName).Points(0).Color = Color.MediumSeaGreen
                Chart1.Series(seriesName).Points(1).Color = Color.PaleGreen
                Chart1.Series(seriesName).Points(2).Color = Color.LawnGreen
                Chart1.Series(seriesName).Points(3).Color = Color.Blue
                Chart1.Series(seriesName).Points(4).Color = Color.Red
                Chart1.Series(seriesName).Points(5).Color = Color.Yellow

                ' Define Chart Type
                Chart1.Series(seriesName).ChartType = DataVisualization.Charting.SeriesChartType.Pie
                Chart1.ChartAreas("ChartArea1").Area3DStyle.Enable3D = True

                ' If you want to show Chart Legends
                Chart1.Legends(0).Enabled = True



                ' If you don't want to show data values and headings as label inside each Pie in chart
                'Chart1.Series(seriesName)("PieLabelStyle") = "Disabled"
                'Chart1.Series("ChartInv").IsValueShownAsLabel = False

                ' If you want to show datavalues as label inside each Pie in chart
                Chart1.Series(seriesName)("PieLabelStyle") = "Enabled"
                Chart1.Series("ChartInv").IsValueShownAsLabel = True

1 个答案:

答案 0 :(得分:0)

计算0

后取Xvalues和Yvalues

例如

考虑变量x,并且此变量的值为0.在这种情况下,不要在xvalues或Yvalues中添加其引用