📅  最后修改于: 2023-12-03 15:16:03.352000             🧑  作者: Mango
The JavaFX stacked area chart is a visualization tool that is used to display the composition of multiple data series over time or any other continuous domain. It is an extension of the area chart where multiple data sets are stacked on top of each other.
The following code demonstrates how to create a basic stacked area chart in JavaFX using the StackedAreaChart
class:
import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.chart.NumberAxis;
import javafx.scene.chart.StackedAreaChart;
import javafx.scene.chart.XYChart;
import javafx.stage.Stage;
public class StackedAreaChartApp extends Application {
@Override
public void start(Stage stage) {
// Create the X and Y axis
NumberAxis xAxis = new NumberAxis();
NumberAxis yAxis = new NumberAxis();
// Create the stacked area chart
StackedAreaChart<Number, Number> areaChart = new StackedAreaChart<>(xAxis, yAxis);
// Add data series to the chart
XYChart.Series<Number, Number> series1 = new XYChart.Series<>();
series1.getData().add(new XYChart.Data<>(1, 50));
series1.getData().add(new XYChart.Data<>(2, 75));
// Add more data points to series1
XYChart.Series<Number, Number> series2 = new XYChart.Series<>();
series2.getData().add(new XYChart.Data<>(1, 30));
series2.getData().add(new XYChart.Data<>(2, 40));
// Add more data points to series2
// Add series to the chart
areaChart.getData().addAll(series1, series2);
// Create and set the scene
Scene scene = new Scene(areaChart, 800, 600);
stage.setScene(scene);
stage.setTitle("Stacked Area Chart Example");
stage.show();
}
public static void main(String[] args) {
launch(args);
}
}
The JavaFX stacked area chart is a powerful tool for visually representing the composition of multiple data series in a continuous domain. With its customizable features and interactive capabilities, programmers can create informative and visually appealing charts for data analysis and presentation.