Divyesh Panchal
Divyesh Panchal

Reputation: 13

How to put Label on Column of chart as shown in image

I want put perfect percentage on each chart column as shown in fig in C# Windows Forms.

[1]: https://i.sstatic.net/cYDGa.png

How would I accomplish this?

Upvotes: 0

Views: 1064

Answers (2)

Akshay
Akshay

Reputation: 1472

Here, try it:

private void fillChart()
{
    //AddXY value in chart1 in series named as Salary  
    chart1.Series["Salary"].Points.AddXY("Ajay", "10000");
    chart1.Series["Salary"].Points.AddXY("Ramesh", "8000");
    chart1.Series["Salary"].Points.AddXY("Ankit", "7000");
    chart1.Series["Salary"].Points.AddXY("Gurmeet", "10000");
    chart1.Series["Salary"].Points.AddXY("Suresh", "8500");
    //chart title  
    chart1.Titles.Add("Salary Chart"); 

    //These lines will show percentages.
    chart1.ChartAreas[0].AxisY.LabelStyle.Format = "{#}%"; 
    chart1.Series["Salary"].IsValueShownAsLabel = true;
    chart1.Series["Salary"].LabelFormat = "{#}%"; 
}

Upvotes: 1

TaW
TaW

Reputation: 54433

In addition to Sak's answer which uses the more powerful formatting, you can get a simple percentage by the Keywords the Chart control provides:

yourSeries.Label = "#PERCENT"; 

Upvotes: 0

Related Questions