Percent value in y axis of Column Chart Microsoft chart control

前端 未结 1 1187
时光说笑
时光说笑 2021-01-19 06:52

I am trying to get Column charts, where I need to have percentage value in y axis and should recalculate and scale.

I have seen some suggestion to assign minimum an

相关标签:
1条回答
  • 2021-01-19 07:30

    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

    enter image description here

    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..

    0 讨论(0)
提交回复
热议问题