zoukankan      html  css  js  c++  java
  • JavaFX Chart设置数值显示

    一、XYChart 


    import javafx.application.Application;
    import javafx.geometry.NodeOrientation;
    import javafx.geometry.Side;
    import javafx.scene.Scene;
    import javafx.scene.chart.*;
    import javafx.scene.control.Label;
    import javafx.stage.Stage;


    public class LineChartSample extends Application {

    @Override
    public void start(Stage stage) {
    stage.setTitle("people");
    final CategoryAxis xAxis = new CategoryAxis();
    final NumberAxis yAxis = new NumberAxis();
    xAxis.setLabel("Country");
    final BarChart<String, Number> chart =
    new BarChart<String, Number>(xAxis, yAxis);

    chart.setTitle("people");

    XYChart.Series series = new XYChart.Series();
    series.setName("flag");
    series.getData().add(new XYChart.Data("China", 14.7));
    series.getData().add(new XYChart.Data("America", 2.5));
    series.getData().add(new XYChart.Data("India", 14));
    XYChart.Data data = new XYChart.Data("Russa", 2);
    data.setNode(new Label("2"));
    series.getData().add(data);

    Scene scene = new Scene(chart, 800, 600);
    chart.getData().addAll(series);

    stage.setScene(scene);
    stage.show();
    }


    public static void main(String[] args) {
    launch(args);
    }
    }
     

    二、PieChart

    import javafx.application.Application;
    import javafx.collections.FXCollections;
    import javafx.collections.ObservableList;
    import javafx.event.EventHandler;
    import javafx.scene.Scene;
    import javafx.scene.control.Label;
    import javafx.scene.input.MouseEvent;
    import javafx.scene.paint.Color;
    import javafx.stage.Stage;
    import javafx.scene.chart.*;
    import javafx.scene.Group;

    public class PieChartSample extends Application {

    @Override public void start(Stage stage) {
    Scene scene = new Scene(new Group());
    stage.setTitle("Imported Fruits");
    stage.setWidth(500);
    stage.setHeight(500);

    ObservableList<PieChart.Data> pieChartData =
    FXCollections.observableArrayList(
    new PieChart.Data("Grapefruit", 13),
    new PieChart.Data("Oranges", 25),
    new PieChart.Data("Plums", 10),
    new PieChart.Data("Pears", 22),
    new PieChart.Data("Apples", 30)
    );

    final PieChart chart = new PieChart(pieChartData);
    chart.setTitle("Imported Fruits");

    final Label caption = new Label("");
    caption.setTextFill(Color.DARKORANGE);
    caption.setStyle("-fx-font: 24 arial;");

    for (final PieChart.Data data : chart.getData()) {
    data.getNode().addEventHandler(MouseEvent.MOUSE_PRESSED,
    new EventHandler<MouseEvent>() {
    @Override public void handle(MouseEvent e) {
    caption.setTranslateX(e.getSceneX());
    caption.setTranslateY(e.getSceneY());
    caption.setText(String.valueOf(data.getPieValue()) + "%");
    }
    });
    }
    ((Group) scene.getRoot()).getChildren().addAll(chart,caption);
    stage.setScene(scene);
    stage.show(http://www.my516.com);
    }

    public static void main(String[] args) {
    launch(args);
    }
    }
    --------------------- 

  • 相关阅读:
    51.N皇后问题
    Record -「CSP-S 2020」赛后总结
    Solution -「洛谷 P4451」「国家集训队」整数的 lqp 拆分
    Solution -「洛谷 P5048」「YunoOI 2019 模拟赛」Yuno loves sqrt technology III
    Solution -「洛谷 P5355」「YunoOI 2017」由乃的玉米田
    Solution -「洛谷 P5610」「YunoOI 2013」大学
    Solution -「洛谷 P5046」「YunoOI 2019 模拟赛」Yuno loves sqrt technology I
    Solution -「洛谷 P5072」「YunoOI 2015」盼君勿忘
    Solution -「洛谷 P4688」「YunoOI 2016」掉进兔子洞
    软件无痕清除目录
  • 原文地址:https://www.cnblogs.com/hyhy904/p/11026619.html
Copyright © 2011-2022 走看看