Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
zhangJiangKai opened this issue Nov 27, 2023 · 1 comment
Closed

Comments

@zhangJiangKai
Copy link

zhangJiangKai commented Nov 27, 2023

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
Copy link
Collaborator

ennerf commented Nov 27, 2023

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.

@ennerf ennerf closed this as completed Nov 27, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants