Better Dashboards

Working with Microsoft enterprise chart, dashboard and reporting technologies.

Starting Y-Axis Labels at a Minimum Value instead of at Zero

Posted by milang on January 10, 2009

Here is a fairly common scenario:  When I was building a stock chart, all of the values for the stock fell between $29 and $34 (I must have been graphing Microsoft’s stock :-)).  By default, the chart calculates labels along the Y-axis based on an algorithm that determines what the highest value in the dataset is, and then sets labels in fixed quantities from 0 to that number.

Unfortunately, when your minimum value is 29, the resulting graph has more white than a Toronto snowstorm:


To solve this issue, some users will hardcode the Y-axis minimum value to the number that they want (in this case, 29).  That works, but there is actually a more elegant solution that is built into the chart: the IsStartedFromZero property on the y-axis changes the labeling algorithm so that the chart recalculates values for the Y-axis labels based on the minimum value in your dataset and the maximum value in your dataset.  The resulting chart is dramatically different:


You can find the property in the property window under ChartAreas –> Axis Collection –> Y-Axis –> IsStartedFromZero or through code:

// Start Y-axis labeling from the minimum value in my dataset
this.Chart2.ChartAreas[0].AxisY.IsStartedFromZero = false;

(Ridiculously obscure sidebar: If you are using a stock chart which uses 4 Y values, and one of those Y values is zero, the IsStartedFromZero property does not work.  So for example, if my first data point in the chart was (X: 0, Y: 32,33,0,0) the chart would not have recalculated axis labels.  As far as I know, this is a bug in the chart.  :-))


4 Responses to “Starting Y-Axis Labels at a Minimum Value instead of at Zero”

  1. […] when we start the y-axis labels at a value other than zero by setting IsStartedFromZero to false, the final result is crystal […]

  2. ryan said

    Thank you for this info. I know this was posted years ago, but I spent hours trying to figure out why my yaxis on my chart was starting at zero. THANKS!

  3. Mian said

    Thats great. I was just looking for it.

  4. PaulW said

    still works in 2016 😉 thanks….

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: