问题描述
我想把数据点的#PERCENT值放在Y轴刻度而不是默认的#VALY。
Hi, i would like to put the #PERCENT value of data points in Y axis scale instead of default #VALY.
这可能吗?
或者我必须回溯图表已经包含百分比值的数据点值?
Or i have to retrive to chart the data points vales already with the percentage value?
示例
数据点1(x,y)=(a,3 )数据点2(x,y)=(b,1)宇宙os 4,所以datapoint1 #PERCENT是75%,datapoint2 #PERCENT是25%我想放入y轴刻度0,25,50,75,100而不是0,1,2,3,4谢谢Hugo
Data point1 (x,y) = (a,3) Data point2 (x, y) = (b,1) The universe os 4, so datapoint1 #PERCENT is 75% and datapoint2 #PERCENT is 25% I want to put in y axis scale 0, 25, 50, 75, 100 instead of 0, 1, 2, 3, 4 Thanks Hugo
推荐答案
这可能是最简单的方法,是的。
This would probably be the easiest way, yes.
否则你将不得不修改生成的标签(使用
自定义标签 href ="http://msdn.microsoft.com/en-us/library/system.windows.forms.datavisualization.charting.chart.customize.aspx">
自定义事件)以反映正确的百分比。
Otherwise you will have to modify the generated labels (using custom labels in the customize event) to reflect the correct precentage.
Private Sub Chart1_Customize(ByVal sender As Object, ByVal e As System.EventArgs) Handles Chart1.Customize
Dim total As Double = 0
Dim s As Series = Chart1.Series(0)
'Calculate total
For Each dp As DataPoint In s.Points
total += dp.YValues(0)
Next
'Modify automatically generated labels
For Each lbl As CustomLabel In Chart1.ChartAreas(0).AxisY.CustomLabels
lbl.Text = String.Format("{0:P2}", ((lbl.FromPosition + lbl.ToPosition) / 2) / total)
Next
End Sub
这篇关于图表使用#PERCENT值而不是默认值#VALY获得y轴刻度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!