Percentage y-axis column chart Microsoft chart control

I am trying to get column charts where I need to have a percentage on the y axis and need to be recalculated and scaled.

I saw some suggestion to assign a minimum and maximum value ( chart.ChartAreas[0].AxisY.Minimum=0), but it does not adjust the height of the column in accordance with the percentage. Any help would be appreciated.

Below is what I have done so far

 foreach (var value in labels)
   {

     chart.Legends[value].Alignment = StringAlignment.Center;
     chart.Legends[value].Docking = Docking.Bottom;
     chart.Series[value].ChartType = SeriesChartType.Column;
     chart.Series[value].IsValueShownAsLabel = true;
     chart.Series[value].Label = "#PERCENT{P0}";

     chart.ChartAreas[0].AxisX.MajorGrid.Enabled = false;
     chart.ChartAreas[0].AxisY.MajorGrid.Enabled =false;
     chart.ChartAreas[0].AxisY.Minimum=0;
      // chart.ChartAreas[0].RecalculateAxesScale();

      chart.BringToFront();

      if (count == 0 && comp.Value != null)
        chart.Series[value].Points.Add(comp.Value[0]);
      else if (count >= 1 && comp.Value != null && comp.Value.Count() > count)
        chart.Series[value].Points.Add(comp.Value[count]);
      else
        chart.Series[value].Points.Add(0);

          count++;
}

column chart The y axis should show the percentage, and the height of the columns should be adjusted by the percentage of the y axis.

+4
source share
1 answer

Here is an example that shows all kinds of information about the data in the chart:

  • X & Y-Values ​​in ToolTip
  • Percentage of total Columns
  • Percentage versus maximum at 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") + "%");
}

, , .

+2

All Articles