如何避免负值与JFreeChart固定的自动范围 [英] How to avoid negative values with JFreeChart fixed auto range

查看:196
本文介绍了如何避免负值与JFreeChart固定的自动范围的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个JFreeChart线图,动态更新我的算法的每次迭代的一个数据点。由于数据点的数量可能很快变得非常大,我已使用 setFixedAutoRange(double)方法。这限制图表显示n个最近的迭代(在我的情况下为200)。

I have a JFreeChart line plot that is updated dynamically with one data point for every iteration of my algorithm. Because the number of data points can quickly become very large, I have used the setFixedAutoRange(double) method on the domain axis. This restricts the graph to displaying the n most recent iterations (200 in my case).

这很好,除非在前200次迭代。问题是,直到有200次迭代,轴包括负值(例如,在50次迭代后,范围是从-150到50)。负迭代没有意义。我想要轴从零开始而不是负值。我如何实现这一点?

This works well, except during the first 200 iterations. The problem is that, until there have been 200 iterations, the axis includes negative values (for example, after 50 iterations, the range is from -150 to 50). Negative iterations make no sense. I would like the axis to start at zero rather than a negative value. How can I achieve this?

我不介意轴是否从0到200最初(图表的右边部分留空,直到绘图填充它是),或者它是从0到1开始增长(使图表总是拉伸在图表的整个宽度)。

I don't mind whether the axis goes from 0 to 200 initially (with the right hand part of the chart left blank until the plot fills it up) or whether it starts at 0 to 1 and grows (so that the plot is always stretched across the full width of the chart). Either would acceptable, though I have a slight preference for the former.

我尝试过的东西:

  • Calling setLowerBound doesn't play nicely with setFixedAutoRange.
  • Calling setRangeType(RangeType.POSITIVE) doesn't seem to make any difference.

任何想法?

推荐答案

像你正在寻找一个解决方案,涉及配置JFreeChart为你做,而不是手动设置范围。

It looks like you're looking for a solution that involves configuring JFreeChart to do it for you, rather than manually setting the range.

我不能帮助...这里有一些其他丑陋的解决方案:P ....

I can't help with that....but here are some other ugly solutions :P ....

你可以做这样的事情(对于伪代码对不起):

You could do something like this (sorry for the pseudo-code):

while(producingData) {
   this.produceData();
   if(!allDataButton.isSelected()) {
      domainAxis.setRange((count < 200) ? 0 : count-200), count);
    } else {
      domainAxis.setRange(0, count);
    }
}



如果我是perl编码器,写这样,只是为了使它更难读:P

If I were a perl-coder, I'd write it like this, just to make it a smidget harder to read :P

while(producingData) {
   this.produceData();
   domainAxis.setRange(
       (((count < 200) || allDataButton.isSelected()) ? 0 : count-200), count);

}

这篇关于如何避免负值与JFreeChart固定的自动范围的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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