本文介绍了JavaFX:如何保持XYChart滴答声不变的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个XYChart,其X轴的刻度单位设置为25。
图表具有滑动功能。每次我向左或向右滑动,我都希望刻度线保持不变。到目前为止,我有10或11个刻度,彼此设置为25个距离,并且它们会改变它们的值 - 我希望它保持不变。

I have a XYChart whose ticks unit is set to 25 for X axis.The chart has a sliding functionality. Each time I slide left or right, I want the ticks to stay constant. So far, I have 10 or 11 ticks, set at 25 distance one to another, and they change their values -- I want that constant.

例如:
lowerBound = 480
upperBound = 600
Ticks:480,505,530,555,580,600。

For example:lowerBound = 480upperBound = 600Ticks: 480, 505, 530, 555, 580, 600.

我向右滑动:I仍然希望在不同的位置看到480,505,530,555,580,600,并且可能摆脱480并且如果我足够向右看到605,630 ......

I slide right: I still want to see 480, 505, 530, 555, 580, 600 at different positions though, and possible get rid of 480 and see 605, 630 if I went enough to the right...

请告知。

推荐答案

修正了:
写了一个类似于NumberAxis的新类,除了calculateTickValues使用我自己的逻辑实现:

Fixed it:wrote a new class similar to NumberAxis, except calculateTickValues is implemented using my own logic:

if (lowerBound + tickUnit < upperBound) {
    double start = lowerBound;
    while ((int)start % (int)tickUnit != 0) {
        start++;
    }
    int count = (int)Math.ceil((upperBound - start)/tickUnit);
    for (int i = 0; start < upperBound && i < count; start += tickUnit, i++) {
         if (!tickValues.contains(start)) {
             tickValues.add((int) start);
         }
    }
}

这里tickUnit = 25,as设置我正在使用的Chart类,它扩展了AbstractBaseChart。
它不是很优雅但是很有效。

Here tickUnit=25, as set up on a Chart class I am using, which extends AbstractBaseChart.It is not very elegant but it works.

这篇关于JavaFX:如何保持XYChart滴答声不变的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-11 20:17