fair-acc / chart-fx

A scientific charting library focused on performance optimised real-time data visualisation at 25 Hz update rates for data sets with a few 10 thousand up to 5 million data points.
GNU Lesser General Public License v3.0
508 stars 94 forks source link

setTickUnit seems to be invalid and does not show the expected effect #648

Closed zhangJiangKai closed 1 year ago

zhangJiangKai commented 1 year ago

hello! I'm having a little difficulty, I hope I can get your help. development environment: jdk17 The pom information is the pom of the main branch image This problem seems to have appeared in #129. I don’t know if it has been fixed? My expectation is to use 30 units as a major scale, which seems to automatically change to 25 units. image

package io.fair_acc.sample;
import io.fair_acc.chartfx.XYChart;
import io.fair_acc.chartfx.axes.spi.DefaultNumericAxis;
import io.fair_acc.chartfx.plugins.Zoomer;
import io.fair_acc.dataset.spi.DoubleDataSet;
import javafx.application.Application;
import javafx.application.Platform;
import javafx.scene.Scene;
import javafx.scene.layout.StackPane;
import javafx.stage.Stage;

public class SimpleChartSample extends Application {

    private static final int N_SAMPLES = 360;

    @Override
    public void start(final Stage primaryStage) {
        final StackPane root = new StackPane();

        final DefaultNumericAxis xAxis = new DefaultNumericAxis("index");
        xAxis.setAutoRanging(false);
        xAxis.setAutoGrowRanging(false);
        xAxis.invertAxis(false);
        xAxis.set(0,360);
        xAxis.setTickUnit(30);

        final DefaultNumericAxis yAxis = new DefaultNumericAxis("Values");
        yAxis.setAutoRanging(true);

        final XYChart chart = new XYChart(xAxis, yAxis);
        root.getChildren().add(chart);

        final DoubleDataSet dataSet1 = new DoubleDataSet("data set #1");

        chart.getPlugins().add(new Zoomer());

        final double[] xValues = new double[N_SAMPLES];
        final double[] yValues1 = new double[N_SAMPLES];
        for (int n = 0; n < N_SAMPLES; n++) {
            xValues[n] = n;
            yValues1[n] = Math.sin(Math.toRadians(n));
        }
        dataSet1.set(xValues, yValues1);

        chart.getDatasets().addAll(dataSet1);

        final Scene scene = new Scene(root, 800, 600);
        primaryStage.setScene(scene);
        primaryStage.show();
        xAxis.tickUnitProperty().addListener((observableValue, number, t1) -> {
            System.out.println("tickUnitProperty:"+number+"----"+t1);
        });
        Platform.runLater(() -> {
            try {
                System.out.println("tickUnit:"+xAxis.getTickUnit());
                Thread.sleep(100);
            } catch (InterruptedException e) {
                throw new RuntimeException(e);
            }
            xAxis.setTickUnit(30);

        });
    }

    public static void main(final String[] args) {
        Application.launch(args);
    }
}
ennerf commented 1 year ago

Sorry, that's an oversight as Axis::setTickUnit is not really part of the public API. The value gets overwriten by the tick computation of the axis itself. You can set it by extending an Axis and overwriting AbstractAxis::computePreferredTickUnit.

This will be addressed in the future and is captured in the TODO list in #622.