Java -- 怎么画图表
可以使用javafx库**
javafx库
-
画图表时怎么设置格式(如点的大小)?
通过css文件定义格式,然后程序读取css中的格式
- 首先创建css文件 bifurcation.css,放置再src下
#bifurcation-diagram .chart-symbol { -fx-background-radius: 10px ; -fx-padding: 10px ; }- 然后在程序中设置相应id,并且获取表单
import javafx.scene.chart.XYChart.Series; import javafx.stage.Stage; public class ScatterChartExample extends Application { @Override public void start(Stage primaryStage) { ScatterChart<Number, Number> chart = new ScatterChart<>(new NumberAxis(), new NumberAxis()); chart.setId("bifurcation-diagram"); // 设置id Series<Number, Number> series = new Series<>(); chart.getData().add(series); for (int i = 0 ; i <= 100; i++) { double lambda = 4.0 * i / 100 ; double x = 0.5 ; for (int j = 0 ; j < 100 ; j++) { x = lambda * x * (1-x); } for (int j = 0 ; j < 50; j++) { series.getData().add(new Data<>(lambda, x)); x = lambda * x * (1-x); } } Scene scene = new Scene(chart, 1200, 800); scene.getStylesheets().add("bifurcation.css"); // 获取表单 primaryStage.setScene(scene); primaryStage.show(); } public static void main(String[] args) { launch(args); } }

浙公网安备 33010602011771号