合理优化的图表缩放 [英] Reasonable optimized chart scaling

查看:126
本文介绍了合理优化的图表缩放的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要做一个图表优化的的轴最大值。

当前方法我有可能使图简单地使用所有的图形的最大值,然后通过10除以它,并将其用作网格线。我没有写出来。

更新说明:这些图形已被更改。当我固定的code,我的动态图形开始工作,使这个问题没有意义的(因为实例不再是他们有过任何错误)。我已经与静态图像更新了这些,但也有一些答案refrence不同的值。记住这一点。 有间12003和14003呼入呼叫至今在二月。信息化,但丑。

我想避免看起来像一只猴子图表想出了的的轴数。

使用谷歌图表API有助于一点点,但它仍然不是完全是我想要的。 替代文字 这些数字是干净的,但该y值的顶部总是相同的图表上的最大值。这个图表刻度从0到1357,我需要计算了1400适当的值,成问题


我扔在<一个href="http://stackoverflow.com/questions/611878/reasonable-optimized-chart-scaling/611979#611979">rbobby's defanition的'好'号在这里,因为它解释得这么好。

  • 在一个好号是一个具有3个或更少的非零数字(如:1230000)
  • 在一个好数量已经大于零的数字相同或几个非零数字(例如:1230不是很好,1200是不错的)
  • 的最好的数字是那些具有3个零的倍数(如1000,百万)
  • 第二个最好的数字是成盎司为3个零加2个零multples(例如150万,1200)

解决方案

我找到了办法让我想用马克赎金的想法修改后的版本的结果。

拳头,马克赎金的code判断刻度之间的最佳间距,在给定的蜱数量。有时,这个数字最终被超过两倍图表上的最高值,这取决于你想要多少网格线。

我在做什么是我跑马克的code,5,6​​,7,8,9,和10个网格线(刻度),以找到那些是最低的。带23的一个值,在图表的高度变为25,具有,网格线5 10,15,20,和25与26的值,图表的高度为30,具有在5网格线,10 ,15,20,25,和30,具有网格线之间的间距相同,但也有更多的人。

因此​​,这里的步骤,刚刚约抄录Excel完全相同,使图表的所有幻想。

  1. 在暂时撞了图表的最高值约5%(这样总有图表的最高点之间的和一些空间图表区的顶部。我们要99.9围捕120)
  2. 找到最佳的网格线位置 5,6,7,8,9,和10格 行。
  3. 挑选出最低的数字。还记得网格线数花了获得该值。
  4. 现在,你有最佳的图表高度。该线/条将永远对接起来反对图表的顶部,你有蜱的最佳数量。

PHP:

 函数综合报告($ maxValue(最大值)){
    $ OPTIMAX = $ maxValue(最大值)* 2;
    为($ i = 5; $ I&LT; = 10; $ I ++){
        $ tmpMaxValue = bestTick($ maxValue(最大值),$ I);
        如果(($特光电&GT; $ tmpMaxValue)和($ tmpMaxValue&GT;($ maxValue(最大值)+ $ maxValue(最大值)* 0.05))){
            $ OPTIMAX = $ tmpMaxValue;
            $ optiTicks = $ I;
        }
    }
    返回$ OPTIMAX;
}
功能bestTick($ maxValue(最大值),$ mostTicks){
    $最小= $ maxValue(最大值)/ $ mostTicks;
    $幅度= POW(10楼(日志($最小)/日志(10)));
    $剩余= $最小/ $幅度;
    如果($残余→5){
        $打勾= 10 * $大小;
    } elseif的($残余→2){
        $打勾= 5 * $大小;
    } elseif的($残余→1){
        $打勾= 2 * $大小;
    } 其他 {
        $打勾= $幅度;
    }
    返程($打勾* $ mostTicks);
}
 

Python的:

 进口数学

高清BestTick(最大,mostticks):
    最小=最大/ mostticks
    大小= 10 ** math.floor(将Math.log(最低)/将Math.log(10))
    剩余=最小/幅度
    如果剩余&GT; 5:
        勾选= 10 *幅度
    ELIF剩余&GT; 2:
        勾选= 5 *级
    ELIF剩余&GT; 1:
        勾选= 2 *幅值
    其他:
        滴答=幅度
    回勾

值= INT(输入())
optMax =值* 2
因为我在范围(5,11):
    包括maxValue = BestTick(值,I)*我
    打印包括maxValue
    如果(optMax&GT;包括maxValue)和(包括maxValue&GT;值+(值* 0.05)):
        optMax =包括maxValue
        optTicks = I
打印\ NTEST值:+ STR(值+(值* 0.05))+\ñ\ nChart高度:+ STR(optMax)+蜱+ STR(optTicks)
 

解决方案

这是从previous类似的问题:

<一个href="http://stackoverflow.com/questions/361681/algorithm-for-nice-grid-line-intervals-on-a-graph">http://stackoverflow.com/questions/361681/algorithm-for-nice-grid-line-intervals-on-a-graph

  

我有一种蛮力的做到了这一点   力法。首先,弄清楚   蜱的最大数量的标记,你可以   适合的空间。除以总   由数值范围   蜱;这是最小   刻度间距。现在计算   底的对数的10到地板   获得蜱的大小,和   该值除以。您应该结束   的东西了在1到的范围内   10.只需选择比循环数大于或等于值和   通过对数乘以   前面计算。这是你的   最后的刻度标记的间隔。

     

例在Python:

 进口数学

高清BestTick(最大,mostticks):
    最小=最大/ mostticks
    大小= 10 ** math.floor(将Math.log(最低)/将Math.log(10))
    剩余=最小/幅度
    如果剩余&GT; 5:
        勾选= 10 *幅度
    ELIF剩余&GT; 2:
        勾选= 5 *级
    ELIF剩余&GT; 1:
        勾选= 2 *幅值
    其他:
        滴答=幅度
    回勾
 

I need to make a chart with an optimized y axis maximum value.

The current method I have of making charts simply uses the maximum value of all the graphs, then divides it by ten, and uses that as grid lines. I didn't write it.

Update Note: These graphs have been changed. As soon as I fixed the code, my dynamic graphs started working, making this question nonsensical (because the examples no longer had any errors in them). I've updated these with static images, but some of the answers refrence different values. Keep that in mind. There were between 12003 and 14003 inbound calls so far in February. Informative, but ugly.

I'd like to avoid charts that look like a monkey came up with the y-axis numbers.

Using the Google charts API helps a little bit, but it's still not quite what I want. The numbers are clean, but the top of the y value is always the same as the maximum value on the chart. This chart scales from 0 to 1357. I need to have calculated the proper value of 1400, problematically.


I'm throwing in rbobby's defanition of a 'nice' number here because it explains it so well.

  • A "nice" number is one that has 3 or fewer non-zero digits (eg. 1230000)
  • A "nice" number has the same or few non-zero digits than zero digits (eg 1230 is not nice, 1200 is nice)
  • The nicest numbers are ones with multiples of 3 zeros (eg. "1,000", "1,000,000")
  • The second nicest numbers are onces with multples of 3 zeros plus 2 zeros (eg. "1,500,000", "1,200")

Solution

I found the way to get the results that I want using a modified version of Mark Ransom's idea.

Fist, Mark Ransom's code determines the optimum spacing between ticks, when given the number of ticks. Sometimes this number ends up being more than twice what the highest value on the chart is, depending on how many grid lines you want.

What I'm doing is I'm running Mark's code with 5, 6, 7, 8, 9, and 10 grid lines (ticks) to find which of those is the lowest. With a value of 23, the height of the chart goes to 25, with a grid line at 5, 10, 15, 20, and 25. With a value of 26, the chart's height is 30, with grid lines at 5, 10, 15, 20, 25, and 30. It has the same spacing between grid lines, but there are more of them.

So here's the steps to just-about copy what Excel does to make charts all fancy.

  1. Temporarily bump up the chart's highest value by about 5% (so that there is always some space between the chart's highest point and the top of the chart area. We want 99.9 to round up to 120)
  2. Find the optimum grid line placement for 5, 6, 7, 8, 9, and 10 grid lines.
  3. Pick out the lowest of those numbers. Remember the number of grid lines it took to get that value.
  4. Now you have the optimum chart height. The lines/bar will never butt up against the top of the chart and you have the optimum number of ticks.

PHP:

function roundUp($maxValue){
    $optiMax = $maxValue * 2;
    for ($i = 5; $i <= 10; $i++){
        $tmpMaxValue = bestTick($maxValue,$i);
        if (($optiMax > $tmpMaxValue) and ($tmpMaxValue > ($maxValue + $maxValue * 0.05))){
            $optiMax = $tmpMaxValue;
            $optiTicks = $i;
        }
    }
    return $optiMax;
}
function bestTick($maxValue, $mostTicks){
    $minimum = $maxValue / $mostTicks;
    $magnitude = pow(10,floor(log($minimum) / log(10)));
    $residual = $minimum / $magnitude;
    if ($residual > 5){
        $tick = 10 * $magnitude;
    } elseif ($residual > 2) {
        $tick = 5 * $magnitude;
    } elseif ($residual > 1){
        $tick = 2 * $magnitude;
    } else {
        $tick = $magnitude;
    }
    return ($tick * $mostTicks);
}

Python:

import math

def BestTick(largest, mostticks):
    minimum = largest / mostticks
    magnitude = 10 ** math.floor(math.log(minimum) / math.log(10))
    residual = minimum / magnitude
    if residual > 5:
        tick = 10 * magnitude
    elif residual > 2:
        tick = 5 * magnitude
    elif residual > 1:
        tick = 2 * magnitude
    else:
        tick = magnitude
    return tick

value = int(input(""))
optMax = value * 2
for i in range(5,11):
    maxValue = BestTick(value,i) * i
    print maxValue
    if (optMax > maxValue) and (maxValue > value  + (value*.05)):
        optMax = maxValue
        optTicks = i
print "\nTest Value: " + str(value + (value * .05)) + "\n\nChart Height: " + str(optMax) + " Ticks: " + str(optTicks)

解决方案

This is from a previous similar question:

http://stackoverflow.com/questions/361681/algorithm-for-nice-grid-line-intervals-on-a-graph

I've done this with kind of a brute force method. First, figure out the maximum number of tick marks you can fit into the space. Divide the total range of values by the number of ticks; this is the minimum spacing of the tick. Now calculate the floor of the logarithm base 10 to get the magnitude of the tick, and divide by this value. You should end up with something in the range of 1 to 10. Simply choose the round number greater than or equal to the value and multiply it by the logarithm calculated earlier. This is your final tick spacing.

Example in Python:

import math

def BestTick(largest, mostticks):
    minimum = largest / mostticks
    magnitude = 10 ** math.floor(math.log(minimum) / math.log(10))
    residual = minimum / magnitude
    if residual > 5:
        tick = 10 * magnitude
    elif residual > 2:
        tick = 5 * magnitude
    elif residual > 1:
        tick = 2 * magnitude
    else:
        tick = magnitude
    return tick

这篇关于合理优化的图表缩放的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆