Choosing an Attractive Linear Scale for Y Axis Charts - More

Next: Choosing an attractive linear scale for the y-axis of the graph

And what to do when some of the points are negative?

I believe that this part of the question was not answered, but it seems that I can not comment or spread this question, so I created a new

Values -100, 0, 100 with 5 ticks: 
  • lower bound = -100
  • upper bound = 100
  • range = 100-100 = 200
  • ticket range = 40
    • Divide by 10 ^ 2 for 0.4, translates by 0.4, which gives (multiplied by 10 ^ 2) 40.
  • new lower bound = 40 * round (-100/40) = -80
  • new upper bound = 40 * round (1 + 100/40) = 120

or

  1. new lower bound = 40 * gender (-100/40) = -120
  2. new upper bound = 40 * gender (1 + 100/40) = 120

Now the range has been increased to 240 (additional tick!), With 5 ticks of 40 each. 6 steps are required to fill in the new range!

Decision

+1
source share
1 answer

I am using the following code. It creates nice intervals for viewers and caters to ranges that go through zero.

 public static class AxisUtil { public static float CalculateStepSize(float range, float targetSteps) { // calculate an initial guess at step size float tempStep = range/targetSteps; // get the magnitude of the step size float mag = (float)Math.Floor(Math.Log10(tempStep)); float magPow = (float)Math.Pow(10, mag); // calculate most significant digit of the new step size float magMsd = (int)(tempStep/magPow + 0.5); // promote the MSD to either 1, 2, or 5 if (magMsd > 5.0) magMsd = 10.0f; else if (magMsd > 2.0) magMsd = 5.0f; else if (magMsd > 1.0) magMsd = 2.0f; return magMsd*magPow; } } 
0
source

All Articles