我显示XYChart JavaFX,其中AxisX和AxisY为数字。
我的数据从(AxisX)开始于103,但图表从0开始。 因此,我只想在数据存在时播放(从103开始显示)
这是我的程序:
//defining the axes
final NumberAxis xAxis = new NumberAxis();
final NumberAxis yAxis = new NumberAxis();
xAxis.setLabel(xLabel);
yAxis.setLabel(yLabel);
//creating the chart
LineChart<Number, Number> lineChart = new LineChart<>(xAxis, yAxis);
lineChart.setTitle(graphTitle);
lineChart.setLegendSide(Side.TOP);
//defining a series
XYChart.Series<Number, Number> series = new XYChart.Series<>();
series.setName(courbeName);
dataFirstCourbe.forEach((value1, value2) -> {
if (!value2.isNaN()) {
XYChart.Data<Number, Number> input = new XYChart.Data<>(value1, value2);
series.getData().add(input);
}
});
Scene scene = new Scene(lineChart, width, height);
// to add CSS
scene.getStylesheets().add(GraphsGenerator.class.getResource("graphs.css").toExternalForm());
lineChart.setAnimated(false);
lineChart.getData().addAll(series, seriesSecond, seriesThree, seriesFour);
// Supprime les points sur la courbe pour plus de lisibilité
for (XYChart.Series<Number, Number> seriesTmp : lineChart.getData()) {
//for all series, take date, each data has Node (symbol) for representing point
for (XYChart.Data<Number, Number> data : seriesTmp.getData()) {
// this node is StackPane
StackPane stackPane = (StackPane) data.getNode();
stackPane.setVisible(false);
}
}
saveAsPng(scene, fileName);
你有个主意吗?