-
Notifications
You must be signed in to change notification settings - Fork 17
/
Copy pathPieChartExample.java
58 lines (44 loc) · 1.78 KB
/
PieChartExample.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
package tutor.javafx;
import javafx.application.Application;
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import javafx.geometry.Side;
import javafx.scene.Scene;
import javafx.scene.chart.PieChart;
import javafx.scene.control.Tooltip;
import javafx.scene.layout.StackPane;
import javafx.stage.Stage;
public class PieChartExample extends Application {
@Override
public void start(Stage primaryStage) {
ObservableList<PieChart.Data> data = FXCollections.observableArrayList();
data.add(new PieChart.Data("OpenCV", 20));
data.add(new PieChart.Data("JavaFX", 40));
data.add(new PieChart.Data("Python", 10));
data.add(new PieChart.Data("Spring", 15));
data.add(new PieChart.Data("Qt", 10));
data.add(new PieChart.Data("SQL", 17));
PieChart pie = new PieChart(data);
pie.setTitle("PieChart Tutorial 2017");
pie.setLegendSide(Side.LEFT);
pie.setTitleSide(Side.BOTTOM);
pie.setLabelLineLength(60);
pie.setLabelsVisible(true);
pie.getData().forEach(this::installTooltip);
StackPane root = new StackPane(pie);
Scene scene = new Scene(root, 800, 600);
scene.getStylesheets().add(getClass().getResource("style.css").toExternalForm());
primaryStage.setTitle("JavaFX PieChart");
primaryStage.setScene(scene);
primaryStage.show();
}
public void installTooltip(PieChart.Data d) {
String msg = String.format("%s : %s", d.getName(), d.getPieValue());
Tooltip tt = new Tooltip(msg);
tt.setStyle("-fx-background-color: gray; -fx-text-fill: whitesmoke;");
Tooltip.install(d.getNode(), tt);
}
public static void main(String[] args) {
launch(args);
}
}