【发布时间】:2019-11-24 05:25:20
【问题描述】:
我想在一个折线图中绘制 4 个系列。每个系列都有大约 100.000 个数据点。现在,使用 javafx linechart,构建图表需要几秒钟。不仅速度慢,而且还非常消耗内存。
有没有人知道如何更快地构建所需的图表。如有必要,我也会使用其他 java 库。
这是一些工作代码。对于 numDataPoints = 10000,它运行良好,但对于 numDataPoints = 70000,它非常慢,甚至崩溃。
提前谢谢你。
import javafx.application.Application;
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import javafx.scene.Scene;
import javafx.scene.chart.NumberAxis;
import javafx.scene.chart.ScatterChart;
import javafx.scene.chart.XYChart;
import javafx.scene.layout.StackPane;
import javafx.stage.Stage;
public class Chart extends Application {
public static void main(String[] args) {
launch(args);
}
@Override
public void start(Stage stage) throws Exception {
prepareStage(stage);
}
private void prepareStage(Stage stage) {
stage.setTitle("JavaFX Chart Demo");
StackPane pane = new StackPane();
NumberAxis xAxis = new NumberAxis();
NumberAxis yAxis = new NumberAxis();
ScatterChart ac = new ScatterChart(xAxis, yAxis);
ac.setTitle("Segregation");
ac.setAnimated(false);
ac.setHorizontalGridLinesVisible(false);
ac.setVerticalGridLinesVisible(false);
int numDataPoints = 70000;
for (int k=0; k<4; k++) {
ObservableList<XYChart.Data<Number, Number>> data = FXCollections.<XYChart.Data<Number, Number>>observableArrayList();
for (int i = 0; i < numDataPoints; i++)
data.add(new XYChart.Data<>(i,Math.random() ));
XYChart.Series series = new XYChart.Series(data);
ac.getData().add(series);
}
pane.getChildren().add(ac);
Scene scene = new Scene(pane, 400, 200);
scene.getStylesheets().add("chart.css");
stage.setScene(scene);
stage.show();
}
}
【问题讨论】:
-
Chart-FX 是新出现的。我跑了一些样本。看起来很有希望。
-
我试过这个,但不幸的是它并没有好转。
标签: java performance javafx charts