尼斯标签算法图表最小刻度 [英] Nice Label Algorithm for Charts with minimum ticks

查看:174
本文介绍了尼斯标签算法图表最小刻度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我想做的事:我需要计算Ticklabels和Tickrange手动图表。

Here is what I want to do: I need to calculate the Ticklabels and the Tickrange for charts manually.

我知道了标准的算法很好的蜱(见<一href="http://books.google.de/books?id=fvA7zLEFWZgC&pg=PA61&lpg=PA61&redir_esc=y#v=onepage&q&f=false">http://books.google.de/books?id=fvA7zLEFWZgC&pg=PA61&lpg=PA61&redir_esc=y#v=onepage&q&f=false)我也知道这个Java实现

I know the "standard" algorithm for nice ticks (see http://books.google.de/books?id=fvA7zLEFWZgC&pg=PA61&lpg=PA61&redir_esc=y#v=onepage&q&f=false) and I also know this Java implementation.

现在的问题是,与这个算法,蜱是太聪明。这意味着,该算法决定多蜱应如何显示。我的要求是,总是有5蜱,但当然这些应该是pretty的。天真appraoch将获得德最大值,5和mulitply与ticknumber分。这里的值是 - 当然 - 不是最佳的,蜱是pretty的丑陋。

The problem is, that with this algorithm, the ticks are "too smart". That means, The algorithm decides how much ticks should be displayed. My requirement is, that there are always 5 Ticks, but these should of course be "pretty". The naive appraoch would be to get teh maximum value, divide with 5 and mulitply with the ticknumber. The values here are - of course - not optimal and the ticks are pretty ugly.

有谁知道这个问题的解决方案,或有提示的正式算法描述?

Does anyone know a solution for the problem or has a hint for a formal algorithm description?

推荐答案

您应该能够用Java实现以较小的修正。

You should be able to use the Java implementation with minor corrections.

更改maxticks为5。

Change maxticks to 5.

更改计算mehod这样:

Change the calculate mehod to this:

private void calculate() {
        this.range = niceNum(maxPoint - minPoint, false);
        this.tickSpacing = niceNum(range / (maxTicks - 1), true);
        this.niceMin =
            Math.floor(minPoint / tickSpacing) * tickSpacing;
        this.niceMax = this.niceMin + tickSpacing * (maxticks - 1); // Always display maxticks
    }

免责声明:请注意,我没有测试过这一点,所以你可能需要调整它,使它看起来不错。我建议的解决方案在图表总是腾出5蜱的顶部增加了额外的空间。这可能看起来很不舒服的情况。

Disclaimer: Note that I haven't tested this, so you may have to tweak it to make it look good. My suggested solution adds extra space at the top of the chart to always make room for 5 ticks. This may look ugly in some cases.

这篇关于尼斯标签算法图表最小刻度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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