none
Chart area interval formatting

    Question

  • Hello,

    I'm trying to format the values listed along the X-Axis and Y-Axis (chart image linked below).  So far i've managed to get the marker intervals consistent along both axes by manually setting the AxisX.Minimum and AxisY.Minimum properties (not shown in the image).  There are a couple of things i'd really like to do that i haven't been able to figure out:

    Firstly, is it possible to format the values to two decimal places?  I'm pulling the values for the series straight out of a database table and would prefer not to format the value in my SQL select but rather in the code.  I tried using FormatNumber() around the values in my call to Points.AddXY() but that was problematic as it seemed to make the X-axis gridline markers disappear altogether.

    Secondly, given that the AxisX.Minimum and AxisY.Minimum values are equal, how would i go about showing the interval markers going up by, say for example, whole numbers.  The chart origin in the image is (14.73~, 14.73~) - is it possible to have the chart show gridlines at 15, 16, 17, 18, ..max(x)/max(y) along X and Y or are we stuck with what the built in algorithm gives us?

    I'm on filtered net access from the office so i had to get a friend to upload this, but hopefully the image is accessible from one of these links:

    - http://i35.tinypic.com/2w559x0.jpg
    - http://tinypic.com/r/2w559x0/4

    Thanking you in advance,
    dj
    Wednesday, November 11, 2009 4:00 AM

Answers

  • The formatting should work as KishorePV showed.. just add a % to the end of the format string for the percentage symbol.

    You can adjust the axis intervals with Axis.IntervalOffset.
    Something like this should work in your case:

    	ChartArea.AxisY.IntervalOffset = -(area.AxisY.Minimum - Math.Truncate(area.AxisY.Minimum))
    	'with a minimum of 14.73 the offset would be -0.73

    You'll lose the AxisY.Minimum label this way though. You could try to add the minimum label in the customize event:

    	Private Sub Chart1_Customize(ByVal sender As Object, ByVal e As System.EventArgs) Handles Chart1.Customize
    
    		Dim chart As Chart = CType(sender, Chart)
    		Dim area As ChartArea = chart.ChartAreas(0)
    
    		area.AxisY.CustomLabels.Add(area.AxisY.Minimum - 0.2, area.AxisY.Minimum + 0.2, area.AxisY.Minimum & "%")
    
    	End Sub
    • Marked as answer by hyperkarma Thursday, November 12, 2009 4:29 AM
    Wednesday, November 11, 2009 10:28 AM
    Moderator

All replies

  • If possible, I'd also like to add a percentage symbol (%) after each x/y axis marker (e.g. 14.73%, 20%, etc.)
    Wednesday, November 11, 2009 4:16 AM
  • Use the following to display values upto 2 decimal points 
    Chart1.ChartAreas(0).AxisY.LabelStyle.Format =

    "{0.00}"


    Please remember to click “Mark as Answer” on the post that helps you, and to click “Unmark as Answer” if a marked post does not actually answer your question. This can be beneficial to other community members reading the thread.
    Wednesday, November 11, 2009 4:58 AM
  • The formatting should work as KishorePV showed.. just add a % to the end of the format string for the percentage symbol.

    You can adjust the axis intervals with Axis.IntervalOffset.
    Something like this should work in your case:

    	ChartArea.AxisY.IntervalOffset = -(area.AxisY.Minimum - Math.Truncate(area.AxisY.Minimum))
    	'with a minimum of 14.73 the offset would be -0.73

    You'll lose the AxisY.Minimum label this way though. You could try to add the minimum label in the customize event:

    	Private Sub Chart1_Customize(ByVal sender As Object, ByVal e As System.EventArgs) Handles Chart1.Customize
    
    		Dim chart As Chart = CType(sender, Chart)
    		Dim area As ChartArea = chart.ChartAreas(0)
    
    		area.AxisY.CustomLabels.Add(area.AxisY.Minimum - 0.2, area.AxisY.Minimum + 0.2, area.AxisY.Minimum & "%")
    
    	End Sub
    • Marked as answer by hyperkarma Thursday, November 12, 2009 4:29 AM
    Wednesday, November 11, 2009 10:28 AM
    Moderator
  • Thanks very much to you both - i managed to resolve the issue with your suggestions :)
    Thursday, November 12, 2009 4:29 AM