用于“好”的算法网格线间隔 [英] Algorithm for "nice" grid line intervals on a graph

查看:141
本文介绍了用于“好”的算法网格线间隔的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要一个合理的智能算法来为图形(图表)提供nice网格线。

I need a reasonably smart algorithm to come up with "nice" grid lines for a graph (chart).

例如,假设条形图的值为您知道:

For example, assume a bar chart with values of 10, 30, 72 and 60. You know:

最小值:10
最大值:72
范围:62

Min value: 10 Max value: 72 Range: 62

第一个问题是:你从什么开始?在这种情况下,0将是直观的值,但这不会阻碍其他数据集,因此我猜猜:

The first question is: what do you start from? In this case, 0 would be the intuitive value but this won't hold up on other data sets so I'm guessing:

网格最小值应为0或一个小于数据范围中的最小值的nice值。

Grid min value should be either 0 or a "nice" value lower than the min value of the data in range. Alternatively, it can be specified.

网格最大值应为高于该范围中最大值的漂亮值。或者,可以指定(例如,如果您显示百分比,则可能希望0到100,而不考虑实际值)。

Grid max value should be a "nice" value above the max value in the range. Alternatively, it can be specified (eg you might want 0 to 100 if you're showing percentages, irrespective of the actual values).

网格线数)应该指定或给定范围内的数字(例如3-8),使得值是nice(即圆号),并最大化使用图表区域。在我们的例子中,80将是一个明智的最大值,因为它将使用90%的图表高度(72/80),而100会创建更多的浪费空间。

The number of grid lines (ticks) in the range should be either specified or a number within a given range (eg 3-8) such that the values are "nice" (ie round numbers) and you maximise use of the chart area. In our example, 80 would be a sensible max as that would use 90% of the chart height (72/80) whereas 100 would create more wasted space.

任何人都知道的一个好的算法呢?

Anyone know of a good algorithm for this? Language is irrelevant as I'll implement it in what I need to.

推荐答案

CPAN提供了一个实现这里(请参阅来源连结)

CPAN provides an implementation here (see source link)

另请参阅 图形轴的Tickmark算法

FYI,您的示例数据:

FYI, with your sample data:


  • Maple:Min = 8,Max = 74,Labels = 10,20,...,60,70,Ticks = 10,12,14,... 70,72

  • < :Min = 10,Max = 80,Labels = 10,20 ,, ..,60,80

这篇关于用于“好”的算法网格线间隔的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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