JavaFX LineChart在高值时显示为空白

时间:2021-02-24 17:00:17

Just encountered an issue with javafx.scene.chart.LineChart. When populating the chart data with Double values above 5E13 or so the series happen to disapear (see screenshot).

刚遇到javafx.scene.chart.LineChart的问题。当使用高于5E13左右的Double值填充图表数据时,系列恰好消失(参见屏幕截图)。

Before JavaFX LineChart在高值时显示为空白

After JavaFX LineChart在高值时显示为空白

Just in case: I'm adding data with the folowing code

以防万一:我正在使用以下代码添加数据

chart.getData().clear();
chart.getData().add(new XYChart.Series<>("Simulation name", sim.getDataAsList()));

It appeared to be that upperBound property of y axis sets to NaN

似乎是y轴的upperBound属性设置为NaN


NumberAxis axis = (NumberAxis) chart.getYAxis();
        axis.upperBoundProperty().addListener(new ChangeListener<Number>() {

            @Override
            public void changed(ObservableValue<? extends Number> observable, Number oldValue, Number newValue) {
                if(Double.isNaN(newValue.doubleValue())){
                    System.out.println("upperBound is NaN");
                }
            }
        });

Please, help anyone!

请帮助任何人!

1 个解决方案

#1


Probably best if you just make a divisor and call your axis billions or something.

如果你只是做一个除数并称你的轴数十亿甚至更多,可能是最好的。

Otherwise you could set the range yourself and provide a formatter.

否则,您可以自己设置范围并提供格式化程序。

Here's a snip from NumberAxis.java

这是NumberAxis.java的一个片段

 /** We use these for auto ranging to pick a user friendly tick unit. We handle tick units in the range of 1e-10 to 1e+12 */
    private static final double[] TICK_UNIT_DEFAULTS = {
        1.0E-10d, ..., 5.0E12d

#1


Probably best if you just make a divisor and call your axis billions or something.

如果你只是做一个除数并称你的轴数十亿甚至更多,可能是最好的。

Otherwise you could set the range yourself and provide a formatter.

否则,您可以自己设置范围并提供格式化程序。

Here's a snip from NumberAxis.java

这是NumberAxis.java的一个片段

 /** We use these for auto ranging to pick a user friendly tick unit. We handle tick units in the range of 1e-10 to 1e+12 */
    private static final double[] TICK_UNIT_DEFAULTS = {
        1.0E-10d, ..., 5.0E12d