饼图图例文字

时间:2012-05-09 20:48:21

标签: asp.net vb.net

我正在尝试在VB.NET中的饼图图例中显示标签名称和百分比。下面是代码。我找不到任何库引用或代码示例来引导我在VB.NET中正确的方向。饼图看起来很好,除此之外。

有人可以帮忙吗?

感谢

    PieTable.Columns.Add("Status")
    PieTable.Columns.Add("Count")
    PieTable.Rows.Add("Pass", LineCounter - FailCnt - WarningCnt)
    PieTable.Rows.Add("Fail", FailCnt)
    PieTable.Rows.Add("Warning", WarningCnt)

    OverallPieChart.DataSource = PieTable
    OverallPieChart.Width = 250
    OverallPieChart.Height = 100
    OverallPieChart.Series("Series1").XValueMember = "Status"
    OverallPieChart.Series("Series1").YValueMembers = "Count"

    OverallPieChart.EnableViewState = True
    OverallPieChart.Series("Series1").ChartType = SeriesChartType.Pie
    OverallPieChart.ChartAreas("ChartArea1").BackColor = Color.Black
    OverallPieChart.ChartAreas("ChartArea1").Area3DStyle.Enable3D = True
    OverallPieChart.BackColor = Color.Black
    'OverallPieChart.Series(0)("PieLabelStyle") = "Outside (#Percent)"
    OverallPieChart.Series(0).LabelForeColor = Color.Beige
    OverallPieChart.ChartAreas("ChartArea1").InnerPlotPosition.Width = 100%
    OverallPieChart.ChartAreas("ChartArea1").InnerPlotPosition.Height = 100%
    OverallPieChart.Series(0)("PieLineColor") = "Transparent"
    OverallPieChart.Series(0)("LabelsRadialLineSize") = "0.15"
    OverallPieChart.Series(0)("LabelsHorizontalLineSize") = "0.15"
    OverallPieChart.Legends.Add("Legent1")
    OverallPieChart.Legends("Legend1").Enabled = True
    OverallPieChart.Legends("Legend1").Docking = Docking.Right
    OverallPieChart.Legends("Legend1").Alignment = System.Drawing.StringAlignment.Far
    OverallPieChart.Legends("Legend1").BackColor = Color.Black

    OverallPieChart.Series("Series1").IsVisibleInLegend = True

2 个答案:

答案 0 :(得分:2)

这应该这样做:

OverallPieChart.Series(0).Label = "#PERCENT"

或者你可以使用它:

OverallPieChart.Series(0).Label = "#PERCENT{P0}"

舍入到最接近的整数

对于标签和百分比:

OverallPieChart.Series(0)Label = "#VALX" & Environment.NewLine & "#PERCENT{P0}"

答案 1 :(得分:1)

您的代码中有拼写错误

OverallPieChart.Legends.Add("Legent1")

应该是

OverallPieChart.Legends.Add("Legend1")