In my project I'm creating multiple AreaCharts as follows:
The thing is maximum count of displayed charts are 10, but length of X axis may vary. In each chart I'm using 4 series:
- one for black ticks
- one for red ticks
- one for green ticks
- last one for occurrence data
The problem is when length of chart's xAxis reaches something about 1200, scrolling the scrollPane is not smooth at all and hardly scrolls.
My question is: Is there any way to make my chart displaying more efficient?
Edit: Layout hierarchy looks like this:
ScrollPane(VBox(Charts))
ETA: Here's standalone version that presents average efficiency with higher count of values displayed in Chart. Note: Running this program may take a few seconds before charts are displayed. How can I possibly make scrolling of these views much smoother?
Program class:
import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.chart.AreaChart;
import javafx.scene.chart.XYChart;
import javafx.scene.control.ScrollPane;
import javafx.scene.layout.VBox;
import javafx.stage.Stage;
public class Program2 extends Application {
public static void main(String[] args) {
launch(args);
}
@Override
public void start(Stage primaryStage) {
try {
ScrollPane scrollPane = new ScrollPane();
VBox vBox = new VBox();
scrollPane.setContent(vBox);
Scene scene = new Scene(scrollPane, 600, 600);
primaryStage.setMaximized(true);
primaryStage.setScene(scene);
primaryStage.show();
for (int i = 0; i < 10; i++) {
CustomChart2 customChart2 = new CustomChart2();
AreaChart.Series<Number, Number> series = new AreaChart.Series<>();
for (int j = 0; j < 2500; j += i + 2) {
series.getData().add(new XYChart.Data<>(j, -0.2));
series.getData().add(new XYChart.Data<>(j, 1));
series.getData().add(new XYChart.Data<>(j + 1, 1));
series.getData().add(new XYChart.Data<>(j + 1, -0.2));
}
customChart2.getData().add(series);
AreaChart.Series<Number, Number> series2 = new AreaChart.Series<>();
for (int j = 0; j < 2500; j += i + 1) {
series2.getData().add(new XYChart.Data<>(j, -0.2));
series2.getData().add(new XYChart.Data<>(j, 1.5));
series2.getData().add(new XYChart.Data<>(j + 0.01, 1.5));
series2.getData().add(new XYChart.Data<>(j + 0.01, -0.2));
}
customChart2.getData().add(series2);
AreaChart.Series<Number, Number> series3 = new AreaChart.Series<>();
for (int j = 2; j < 2500; j += i + 1) {
series3.getData().add(new XYChart.Data<>(j, -0.2));
series3.getData().add(new XYChart.Data<>(j, 1.2));
series3.getData().add(new XYChart.Data<>(j + 0.01, 1.2));
series3.getData().add(new XYChart.Data<>(j + 0.01, -0.2));
}
customChart2.getData().add(series3);
vBox.getChildren().add(customChart2);
}
} catch (Exception e) {
e.printStackTrace();
}
}
}
Modified chart class:
import javafx.scene.chart.AreaChart;
import javafx.scene.chart.NumberAxis;
public class CustomChart2 extends AreaChart<Number, Number> {
private NumberAxis xAxis;
private NumberAxis yAxis;
public CustomChart2() {
super(new NumberAxis(0, 2500, 5), new NumberAxis(0, 1.5, 1.5));
this.xAxis = (NumberAxis) getXAxis();
this.yAxis = (NumberAxis) getYAxis();
configure();
configureXAxis();
configureYAxis();
}
private void configure() {
setAnimated(false);
setCreateSymbols(false);
setMinWidth(2500 * 20);
computeMaxHeight(60);
setMaxHeight(60);
maxHeight(60);
setMinHeight(60);
setHorizontalGridLinesVisible(false);
setVerticalGridLinesVisible(false);
setLegendVisible(false);
setVerticalZeroLineVisible(false);
setHorizontalZeroLineVisible(false);
}
private void configureXAxis() {
xAxis.setAutoRanging(false);
}
private void configureYAxis() {
yAxis.setPrefSize(0, 0);
yAxis.setAutoRanging(false);
yAxis.setTickMarkVisible(false);
yAxis.setTickLabelsVisible(false);
yAxis.setMinorTickVisible(false);
}
}