views:

219

answers:

2

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.

+1  A: 

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

Avatar
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.
Guy
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.HTH
Avatar
Tada... I've got it I guess. please check this link. This might be helpful for you.http://support2.dundas.com/Default.aspx?article=1062
Avatar
ChartArea.AxisY.LabelStyle.Format ="#.##";http://msdn.microsoft.com/en-us/library/0c899ak8.aspxhttp://msdn.microsoft.com/en-us/library/dwhawy9k.aspxHope these links help in future as well :)
Avatar
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.
Guy
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...
Guy
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!
Guy
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.
Guy
Very glad indeed :)
Avatar
+1  A: 

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); 
Guy
+1 This is great:)
Avatar