Percent value in y axis of Column Chart Microsoft chart control

笑着哭i 提交于 2019-12-01 18:46:33

Here is an example that shows all sorts of info about the data in the chart:

  • The X&Y-Values in a ToolTip
  • The percentages of the the values against the total on the Columns
  • The percentage against the maximum at the Y-Axis

Series S = chart1.Series[0];
ChartArea CA = chart1.ChartAreas[0];
Axis AY = CA.AxisY;

S.Points.AddXY(1, 10);      S.Points.AddXY(2, 40);
S.Points.AddXY(3, 50);      S.Points.AddXY(4, 100);
S.Points.AddXY(5, 111);  

S.IsValueShownAsLabel = true;
S.Label = "#PERCENT{P0}";

S.ToolTip = "#VALX{#.##}" + " : " + "#VALY1{#.##}";

double max = S.Points.Max(x => x.YValues[0]);

for (int i = 0; i < S.Points.Count; i++)
{
    DataPoint dp =  S.Points[i];
    double y0 = S.Points[i].YValues[0];
    AY.CustomLabels.Add(y0, y0 + 1, (y0 / max * 100f).ToString("0.0") + "%");
}

Of course you can change it all around as you please..

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!