码迷,mamicode.com
首页 > 其他好文 > 详细

设置数值显示

时间:2019-07-31 19:08:44      阅读:237      评论:0      收藏:0      [点我收藏+]

标签:getchild   imp   int   ati   eval   for   import   ide   java   


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(http://www.my516.com/heimitao/)).getChildren().addAll(chart,caption);
stage.setScene(scene);
stage.show();
}

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

设置数值显示

标签:getchild   imp   int   ati   eval   for   import   ide   java   

原文地址:https://www.cnblogs.com/liyanyan665/p/11278056.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!