.Net DataVisualization.Charting Formatting values on Y-Axis
Asked Answered
H

2

7

Does anybody know how to format and control the values shown on the Y-Axis of a .Net 4 DataVisualization.Charting chart?

I have values on the Y-Axis and dates on the X-Axis. The values on the Y-Axis are showing multiple decimal points and I want to apply a custom formatter to them so that I can show them in any format I want. So for example I can show 1+3/4 instead of 1.75.

I am doing all of the chart generation in code using a Chart object from the System.Web.UI.DataVisualization.Charting namespace.

Holbrooke answered 21/8, 2010 at 6:15 Comment(0)
H
4

I found the answer, there's a Customize delegate that can be setup which is called after all data members have been calculated and before the chart is rendered. If you attach your delegate to the Chart's Customize event you'll be able to do all the customization you want in there.

this.Chart1.Customize +=new EventHandler(this.Chart1_Customize); 
Holbrooke answered 4/9, 2010 at 2:37 Comment(0)
S
8

You have to set the Format property of LabelStyle in the respective axis.

In your case, like below.

ChartArea.AxisY.LabelStyle.Format = "{0.00}";

Please refer the links below for further details.

(Refer the answer by Kishore)
http://social.msdn.microsoft.com/Forums/en-US/MSWinWebChart/thread/8f843a18-c72e-4cc1-9fcc-7ad0d9e39c15#5fcef069-7ea7-4d73-9611-90bf9e14ede3

HTH

Spit answered 2/9, 2010 at 16:30 Comment(8)
Thanks Avatar +1 - that gets me closer to what I'm looking for but not there just yet. That will allow me format a number to x decimal places but it will not allow me to convert the format to fractions for example. i.e. I could not represent 1.75 as 1+3/4 on the Y axis with that format.Holbrooke
If I'm right, microsoft is using Dundas charts. So, you have a good chance of finding the related content from their forums or blogs. HTHSpit
Tada... I've got it I guess. please check this link. This might be helpful for you. support2.dundas.com/Default.aspx?article=1062Spit
ChartArea.AxisY.LabelStyle.Format ="#.##"; msdn.microsoft.com/en-us/library/0c899ak8.aspx msdn.microsoft.com/en-us/library/dwhawy9k.aspx Hope these links help in future as well :)Spit
That still doesn't allow me to apply a custom format that I created. So, for example, if I had the values 1 through 9 on the Y Axis and instead I wanted the word in a specific language instead of the number: "uno", "dos", "tres"... etc. I would expect that the object would have allow me to attach a delegate or specify a callback function that I would write that would allow me to do the formatting and pass back the string.Holbrooke
I have also discovered the ChartArea.AxisY.CustomLabels collection but this is readonly so I'm not sure how it should be used. Investigating this now...Holbrooke
Avatar, I marked this answer as correct so that you'd get the 50 points for helping out. You got half way there and if you look at my answer you'll see how I finished it off - thanks for all your help!Holbrooke
Turns out that I didn't have to mark this answer as correct to give you the bounty so I unmarked it as correct but gave you the bounty anyway.Holbrooke
H
4

I found the answer, there's a Customize delegate that can be setup which is called after all data members have been calculated and before the chart is rendered. If you attach your delegate to the Chart's Customize event you'll be able to do all the customization you want in there.

this.Chart1.Customize +=new EventHandler(this.Chart1_Customize); 
Holbrooke answered 4/9, 2010 at 2:37 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.