내가 JavaFX
에 LineChart
에 몇 가지 기능을 추가하고 있는데 차트 Axis
에서 대부분이 방법을 사용하고 있습니다 :차트 데이터가 표시되는시기를 아는 방법은 무엇입니까?
- 축 # getDisplayPosition
- 축 # getValueForDisplay
문제를이 방법입니다 차트에 추가 한 새 데이터가 렌더링 될 때만 올바른 값을 반환합니다. 그래서 지금이 추한 해결 방법이 있습니다
new Timer().schedule(new TimerTask() {
@Override
public void run() {
Platform.runLater(new Runnable() {
@Override
public void run() {
// Axis#getDisplayPosition and Axis#getValueForDisplay usage
}
});
}
}, 10);
적어도 내가이 방법을 사용할 수 있습니다 새로운 데이터가 화면에 렌더링 할 내 PC에 충분한 코드 10mS에의 실행을 지연 타이머. 차트가 렌더링 될 때를 알 수있는 다른 방법이 있습니까? 나는 LineChart
에서 오버 라이딩 할 수있는 모든 메소드를 찾고 있었지만, 차트 작성이 완료되면 알 수있는 도움말을 찾을 수 없습니다. 여기
import javafx.application.Application;
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import javafx.event.EventHandler;
import javafx.scene.Scene;
import javafx.scene.chart.LineChart;
import javafx.scene.chart.NumberAxis;
import javafx.scene.chart.XYChart;
import javafx.scene.input.MouseEvent;
import javafx.scene.layout.Pane;
import javafx.stage.Stage;
import java.util.Random;
public class Main extends Application {
@Override
public void start(final Stage primaryStage) throws Exception{
final LineChart lineChart = new LineChart(new NumberAxis(), new NumberAxis());
final XYChart.Series<Integer, Integer> series = new XYChart.Series<Integer, Integer>();
ObservableList<XYChart.Series<Integer, Integer>> seriesDataSet = FXCollections.observableArrayList();
lineChart.setAnimated(false);
lineChart.setPrefWidth(800);
lineChart.setPrefHeight(600);
seriesDataSet.add(series);
lineChart.setData(seriesDataSet);
for (int n = 0; n < 50; ++n) {
series.getData().add(new XYChart.Data<Integer, Integer>(n, new Random().nextInt(20)));
}
Pane pane = new Pane();
pane.getChildren().add(lineChart);
primaryStage.setScene(new Scene(pane, 800, 600));
primaryStage.show();
// Get a display
System.out.println(lineChart.getXAxis().getDisplayPosition(2));
// The value is now correct and different from the previous one
System.out.println(lineChart.getXAxis().getDisplayPosition(2));
// Add data to the chart
for (int n = 51; n < 80; ++n) {
series.getData().add(new XYChart.Data<Integer, Integer>(n, new Random().nextInt(20)));
}
// Get a display
System.out.println(lineChart.getXAxis().getDisplayPosition(2));
// The value is now correct and different from the previous one
System.out.println(lineChart.getXAxis().getDisplayPosition(2));
pane.setOnMouseClicked(new EventHandler<MouseEvent>() {
@Override
public void handle(MouseEvent mouseEvent) {
System.out.println(lineChart.getXAxis().getDisplayPosition(2));
}
});
}
public static void main(String[] args) {
launch(args);
}
}
처음 두 숫자를, 나는 일부 데이터를 같은 추가되어 인쇄, 숫자는 여전히 그들이해야 잘못되는 동일 데이터를 추가 했으므로 이전의 것과 다를 수 있습니다. 이제 차트의 어딘가를 클릭하면 차트가 이미 렌더링되었으므로 올바른 번호를 읽을 수 있습니다.
[차트에서 애니메이션 끄기] (http://docs.oracle.com/javase/8/javafx/api/javafx/scene/chart/Chart.html#setAnimated-boolean-)를 시도 했습니까? – jewelsea
예, 차트에 애니메이션이 적용되지 않았습니다. – Andres
[최소, 완전 검증 가능한 예제 (mcve)] (http://stackoverflow.com/help/mcve)를 제공하기 위해 질문을 편집 할 수 있습니까? – jewelsea