📅  最后修改于: 2023-12-03 14:42:22.104000             🧑  作者: Mango
JavaFX Bubble Chart is a JavaFX chart type that is used to display data in a series of bubbles. Each bubble represents a data point, with the size and color of the bubble indicating the value of the data point.
To create a Bubble Chart in JavaFX, you need to use the BubbleChart
class. The class takes two parameters, which are the x-axis and y-axis values. To add data to the chart, you can create a series of the XYChart.Series
class and then add data to it using the Data
class.
//creating the bubble chart
BubbleChart<Number,Number> bubbleChart = new BubbleChart<>(xAxis,yAxis);
//defining the series
XYChart.Series<Number, Number> series = new XYChart.Series<Number, Number>();
//populating the series with data
series.getData().add(new XYChart.Data<Number, Number>(3, 1, 0.5));
series.getData().add(new XYChart.Data<Number, Number>(4, 2, 0.3));
series.getData().add(new XYChart.Data<Number, Number>(2, 4, 0.7));
series.getData().add(new XYChart.Data<Number, Number>(6, 5, 0.9));
series.getData().add(new XYChart.Data<Number, Number>(5, 8, 0.1));
//adding the series to the bubble chart
bubbleChart.getData().add(series);
You can customize the Bubble Chart by changing its appearance, adding titles, and axis labels. You can also change the color and size of the bubbles based on the data values.
//setting the title of the bubble chart
bubbleChart.setTitle("Sample Bubble Chart");
//setting the labels of the x and y axis
xAxis.setLabel("X-Axis");
yAxis.setLabel("Y-Axis");
//customizing the bubbles
for (final XYChart.Series<Number,Number> series : bubbleChart.getData()) {
for (final XYChart.Data<Number,Number> data : series.getData()) {
final Node bubble = data.getNode();
final double bubbleSize = 20.0 * data.getYValue().doubleValue();
bubble.setStyle("-fx-background-color: " + seriesNameToColor.get(series.getName()) + "; -fx-background-radius: " + bubbleSize + "; -fx-border-radius: " + bubbleSize + ";");
}
}
JavaFX Bubble Chart is a great tool for visualizing data in a series of bubbles. It is easy to create and customize, allowing you to make beautiful and informative charts.