如何在VB.NET中以百分比显示饼图标签值? [英] How to Show Pie Chart Label Values in Percentage in VB.NET ?

查看:183
本文介绍了如何在VB.NET中以百分比显示饼图标签值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好!



我在VB.NET 2010中工作。

我使用MS Chart Control绘制饼图。

饼图是从包含四个记录的表中获得的数据......

ie

ColorName NumberofItems

绿色100

蓝色200

红色300

黄色400



总项目数= 1000



我的饼图显示结果为......



绿色100

蓝色200

红色300

黄色400



但我希望看到结果百分比如...



绿色100(1.00%)

蓝色200(2.00) %)

红色300(3.00%)

黄色400(40.00%)



i尽我所能但是我找不到解决方案。



有人能解决我的问题吗?



谢谢!



最好的问候:

Muhammad Asim Mughal

解决方案

嗯,计算百分比的公式是:

  Dim  v1  As   Double  =  100  
Dim v2 作为 Double = 200
Dim v3 As Double = 300
Dim v4 As Double = 400
Dim 总计作为 Double = v1 + v2 + v3 + v4
Dim p1 As Double = v1 / total ' 'p1 = 100/1000 = 0.1
Dim p2 As < span class =code-keyword> Double = v2 / total ' 'p2 = 200/1000 = 0.2
Dim p3 作为 Double = v3 / total ' 'p3 = 300/1000 = 0.3
Dim p4 作为 Double = v4 / total ' 'p4 = 400/1000 = 0.4
Dim p1Display As String = p1.ToString(< span class =code-string> P' 'p1Display =10.00%
Dim p2Display As 字符串 = p2.ToString( P' 'p2Display =20.00%
Dim p3Display As String = p3.ToString( P' 'p3Display =30.00%
Dim p4Display As String = p4.ToString( P' 'p4Display =40.00%



重要这里指出:

- 计算其主要真实形式的百分比值。如果必须将其保存在存储库中,请保留其实际值,而不是其字符串表示。

- 仅在向用户显示值时将其显示为百分比。在这里,我使用 ToString(P)方法来告诉我想要基础实际值的百分比表示。

- 概念以上两点对所有类型的数据都有效,尤其是日期时间。总是处理和存储日期时间值,而不是它们的字符串表示。



最后,因为它是你的问题更多的是数学问题而不是开发问题。请注意,我建议你提高你的数学技能;作为开发者,它将使您的日常生活变得更加轻松。



希望这会有所帮助。干得好:)



要将百分比格式应用于图表标签,你可以这样做:

 yourChart.ChartAreas.First()。AxisY.LabelStyle.Format =   P 


Hello !

I am working in VB.NET 2010.
I am using MS Chart Control to Draw a Pie Chart.
The pie chart is given the data from a table that contains four records ...
i.e.
ColorName NumberofItems
Green 100
Blue 200
Red 300
Yellow 400

Total Items=1000

My pie chart is showing the results as ....

Green 100
Blue 200
Red 300
Yellow 400

but i want to see the result in percentage like...

Green 100 (1.00%)
Blue 200 (2.00%)
Red 300 (3.00%)
Yellow 400 (40.00%)

i tried my best but i could not find the solution.

Can anyone solve my problem ?

Thanks!

Best Regards:
Muhammad Asim Mughal

解决方案

Well, the formula to compute a percentage is:

Dim v1 As Double = 100
Dim v2 As Double = 200
Dim v3 As Double = 300
Dim v4 As Double = 400
Dim total As Double = v1 + v2 + v3 + v4
Dim p1 As Double = v1 / total '' p1 = 100 / 1000 = 0.1
Dim p2 As Double = v2 / total '' p2 = 200 / 1000 = 0.2
Dim p3 As Double = v3 / total '' p3 = 300 / 1000 = 0.3
Dim p4 As Double = v4 / total '' p4 = 400 / 1000 = 0.4
Dim p1Display As String = p1.ToString("P") '' p1Display = "10.00%"
Dim p2Display As String = p2.ToString("P") '' p2Display = "20.00%"
Dim p3Display As String = p3.ToString("P") '' p3Display = "30.00%"
Dim p4Display As String = p4.ToString("P") '' p4Display = "40.00%"


Important points here:
- Compute the percent value in its primary, real form. If you have to save it in a repository, keep its real value, not its string representation.
- Display it as a percent only when you are presenting the value to the user. Here I used the ToString("P") method to tell that I want the percent-representation of the underlying real value.
- The concept in two points above is valid for all types of data, and especially datetimes. Always handle and store datetime values, not their string representation.

Finally, as it is your question is more a mathematic question than a development one. Kindly, I advise you to improve your skills in mathematics; as a developper, it will make your every-day life way much easier.

Hope this helps. Good work :)

[Edit] To apply the percentage format to a chart label, you can do it this way:

yourChart.ChartAreas.First().AxisY.LabelStyle.Format = "P"


这篇关于如何在VB.NET中以百分比显示饼图标签值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆