ASP图表StackedColumn100在值上添加百分号(%)

时间:2016-02-02 22:32:45

标签: c# asp.net charts microsoft-chart-controls

我有这个图表(在.NET上使用Chart控件内置):

enter image description here

如何在所有值后面添加百分号(%)(例如44 => 44%,56 => 56%等)

修改(在评论中尝试了jstreet之后):StackedColumn100图表,因此值已经是百分比。

尝试<asp:Series Label="#VAL%">,得到了这个:(注意0值显示我不想要,我使用这些代码最初隐藏那些0值):

protected void RequestChart_Customize(object sender, EventArgs e)
        {
            //hide label value if zero
            foreach (System.Web.UI.DataVisualization.Charting.Series series in RequestChart.Series)
            {
                foreach (System.Web.UI.DataVisualization.Charting.DataPoint point in series.Points)
                {
                    if (point.YValues.Length > 0 && (double)point.YValues.GetValue(0) == 0)
                    {
                        point.IsValueShownAsLabel = false;
                    }
                }
            }
        }

enter image description here

尝试<asp:Series LabelFormat="P2">,得到了这个

enter image description here

1 个答案:

答案 0 :(得分:0)

这对我有用:LabelFormat="{0}%",将{0}更改为{0.0}{0.00},具体取决于您希望如何显示这些值。

顺便说一句,要在图表上隐藏0值,请将此Customize事件添加到图表中:

protected void RequestChart_Customize(object sender, EventArgs e)
        {
            //hide label value if zero
            foreach (System.Web.UI.DataVisualization.Charting.Series series in RequestChart.Series)
            {
                foreach (System.Web.UI.DataVisualization.Charting.DataPoint point in series.Points)
                {
                    if (point.YValues.Length > 0 && (double)point.YValues.GetValue(0) == 0)
                    {
                        point.IsValueShownAsLabel = false;
                    }
                }
            }
        }