如何在JavaFX中创建带有两个参数的气泡图?
例
以下是一个JavaFX示例,演示了如何创建带有两个值的气泡图-
import javafx.application.Application; import javafx.geometry.Insets; import javafx.scene.Scene; import javafx.stage.Stage; import javafx.scene.chart.BubbleChart; import javafx.scene.chart.NumberAxis; import javafx.scene.chart.XYChart; import javafx.scene.layout.StackPane; public class BubbleChart_TwoParams extends Application { public void start(Stage stage) { //Creating the X and Y axes NumberAxis xAxis = new NumberAxis(5, 25, 5); NumberAxis yAxis = new NumberAxis(50, 90, 5); //Setting labels to the axes xAxis.setLabel("Temperature °C"); yAxis.setLabel("Ice Cream Sales in (USD)"); //Creating the Scatter chart BubbleChart bubbleChart = new BubbleChart(xAxis, yAxis); //Preparing data for the scatter chart XYChart.Series series = new XYChart.Series(); series.getData().add(new XYChart.Data(15.2, 72.79)); series.getData().add(new XYChart.Data(8.39, 83.97)); series.getData().add(new XYChart.Data(20.6, 67.14)); series.getData().add(new XYChart.Data(15.8, 80.32)); series.getData().add(new XYChart.Data(10.4, 87.27)); //Setting the data to scatter chart bubbleChart.getData().add(series); //Setting title to the scatter chart //scatterChart.setTitle("Ice Cream Sales vs Temperature"); //Setting name to the series series.setName("Temperatue vs Icecream Sales"); //Creating a stack pane to hold the chart StackPane pane = new StackPane(bubbleChart); pane.setPadding(new Insets(15, 15, 15, 15)); pane.setStyle("-fx-background-color: BEIGE"); //Setting the Scene Scene scene = new Scene(pane, 595, 300); stage.setTitle("Bubble Chart"); stage.setScene(scene); stage.show(); } public static void main(String args[]){ launch(args); } }
输出结果