ASP.NET Chart Add Percent Next To Number

I have a chart control that displays columns with values ​​at the top (series with labels). These values ​​come from the database, and they are already in percentage format (i.e.: display 12.54 not 0.1254)

I want to add "%" next to the numbers.

when I try to use the "LabelFormat" property and set it to "P2", I get these numbers:

1254.00% !!

I think P2 does some calculations!

I just want to add the "%" symbol next to the number. what he

can anyone help?

+6
source share
5 answers

Ok, I found the answer myself! thanks for all..

Here's the answer:

to simply display "%" next to the number, simply follow these steps:

Chart1.Series["MySeries"].Label = "#VALY"+"%"; 

OR (for the Y axis, for example :)

 Chart1.ChartAreas[0].AxisY.LabelStyle.Format = "{#}%"; 

It worked great for me!

+6
source

Combining Yousi Solution with Alex Z Solution

If your value is in decimal format, for example. 0.14 = 14%, then use this markup:

  <ChartAreas> <asp:ChartArea Name="ChartArea1"> <AxisY > <LabelStyle Format="{0:p}" /> </AxisY> </asp:ChartArea> </ChartAreas> 

If your value is the actual number you would like to see, just with% after using it:

  <ChartAreas> <asp:ChartArea Name="ChartArea1"> <AxisY > <LabelStyle Format="{#}%" /> </AxisY> </asp:ChartArea> </ChartAreas> 

i.e. If you try the first block of code above and see values, for example, 1000%, where you expect 10% to use the second.

+3
source

The format specifier "P" takes a number and treats it as a percentage, so 1 will be converted to 100%. Can you return a percentage equal to 0.1254?

+2
source

Better use below to avoid multiplying percentages by 100

  <ChartAreas> <asp:ChartArea Name="ChartArea1"> <AxisY > <LabelStyle Format="{p0}" /> </AxisY> </asp:ChartArea> </ChartAreas> 
+1
source
  <ChartAreas> <asp:ChartArea Name="ChartArea1"> <AxisY > <LabelStyle Format="{0:p}" /> </AxisY> </asp:ChartArea> </ChartAreas> 
0
source

Source: https://habr.com/ru/post/901372/


All Articles