下面列出了javafx.scene.chart.PieChart#Data ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
private void addDiskBox(Disk disk) {
try {
Parent parentDisk = FXMLLoader.load(getClass().getResource("/resources/views/models/DiskInfo.fxml"));
//Label lblName = (Label) parentDisk.lookup("#lblName");
Label lblTotalSpace = (Label) parentDisk.lookup("#lblTotalSpace");
PieChart pieData = (PieChart) parentDisk.lookup("#pieData");
pieData.setTitle(disk.getName());
lblTotalSpace.setText(Utils.humanReadableByteCount(disk.getTotalSpace()));
// Data of pie chart
ObservableList<PieChart.Data> data = FXCollections.observableArrayList();
data.add(new PieChart.Data("Usable", Utils.humanReadableByteCountNumber(disk.getUsableSpace())));
data.add(new PieChart.Data("Free", Utils.humanReadableByteCountNumber(disk.getFreeSpace())));
pieData.setData(data);
pieData.getData().forEach(d ->
d.nameProperty().bind(Bindings.concat(d.getName(), " ", d.pieValueProperty(), " GB"))
);
boxContainerDisks.getChildren().add(parentDisk);
} catch (IOException ioe) {
ioe.printStackTrace();
}
}
private void updateInnerCircleLayout() {
double minX = Double.MAX_VALUE, minY = Double.MAX_VALUE;
double maxX = Double.MIN_VALUE, maxY = Double.MIN_VALUE;
for (PieChart.Data data: getData()) {
Node node = data.getNode();
Bounds bounds = node.getBoundsInParent();
if (bounds.getMinX() < minX) {
minX = bounds.getMinX();
}
if (bounds.getMinY() < minY) {
minY = bounds.getMinY();
}
if (bounds.getMaxX() > maxX) {
maxX = bounds.getMaxX();
}
if (bounds.getMaxY() > maxY) {
maxY = bounds.getMaxY();
}
}
innerCircle.setCenterX(minX + (maxX - minX) / 2);
innerCircle.setCenterY(minY + (maxY - minY) / 2);
innerCircle.setRadius((maxX - minX) / 4);
}
public static void setPieColors(PieChart pie, List<String> palette,
boolean showLegend) {
if (pie == null || palette == null
|| pie.getData() == null
|| pie.getData().size() > palette.size()) {
return;
}
for (int i = 0; i < pie.getData().size(); i++) {
PieChart.Data data = pie.getData().get(i);
data.getNode().setStyle("-fx-pie-color: " + palette.get(i) + ";");
}
pie.setLegendVisible(showLegend);
if (showLegend) {
Set<Node> legendItems = pie.lookupAll("Label.chart-legend-item");
if (legendItems.isEmpty()) {
return;
}
for (Node legendItem : legendItems) {
Label legendLabel = (Label) legendItem;
Node legend = legendLabel.getGraphic();
if (legend != null) {
for (int i = 0; i < pie.getData().size(); i++) {
String name = pie.getData().get(i).getName();
if (name.equals(legendLabel.getText())) {
legend.setStyle("-fx-background-color: " + palette.get(i));
break;
}
}
}
}
}
}
/**
* Generates a pie chart with the summary test results of the current build.
*
* @param passedCount passed test count
* @param failedCount failed test count
* @param skippedCount skipped test count
* @param summaryChartFileName file name of the summary chart
*/
public void generateSummaryChart(int passedCount, int failedCount, int skippedCount, String summaryChartFileName) {
List<PieChart.Data> data = new ArrayList<>();
data.add(new PieChart.Data(StringUtil.concatStrings("Test Failures (", Integer.toString(failedCount), ")"),
failedCount));
data.add(new PieChart.Data(StringUtil.concatStrings("Deployment Errors (", Integer.toString
(skippedCount), ")"), skippedCount));
data.add(new PieChart.Data(StringUtil.concatStrings("Passed (", Integer.toString(passedCount), ")"),
passedCount));
ObservableList<PieChart.Data> pieChartData = FXCollections.observableArrayList(data);
final PieChart chart = new PieChart(pieChartData);
chart.setAnimated(false);
chart.setLabelsVisible(true);
chart.setTitle("Build Summary of Infrastructure Combinations ("
+ (failedCount + skippedCount + passedCount) + ")");
genChart(chart, 600, 600, summaryChartFileName, "styles/summary.css");
}
@SuppressWarnings("unchecked")
@Override
public void initialize(URL location, ResourceBundle resources) {
ObservableList<PieChart.Data> pieChartData = FXCollections.observableArrayList(
new PieChart.Data("Sun", 20),
new PieChart.Data("IBM", 12),
new PieChart.Data("HP", 25),
new PieChart.Data("Dell", 22),
new PieChart.Data("Apple", 30)
);
pieChart.setData(pieChartData);
pieChart.setClockwise(false);
XYChart.Series<String, Number> series = new XYChart.Series<>();
series.setName("Legend 1");
series.getData().add(new XYChart.Data<>("0", 2D));
series.getData().add(new XYChart.Data<>("1", 8D));
series.getData().add(new XYChart.Data<>("2", 5D));
series.getData().add(new XYChart.Data<>("3", 3D));
series.getData().add(new XYChart.Data<>("4", 6D));
series.getData().add(new XYChart.Data<>("5", 8D));
series.getData().add(new XYChart.Data<>("6", 5D));
series.getData().add(new XYChart.Data<>("7", 6D));
series.getData().add(new XYChart.Data<>("8", 5D));
areaChart.getData().setAll(series);
areaChart.setCreateSymbols(true);
}
@FXML
private void setPieChartGraph(){
Integer chartType = chbxTest.getValue();
//switch by vehicle type
switch (chartType){
case 1 :
ObservableList<PieChart.Data> pieChartData = FXCollections.observableArrayList(
new PieChart.Data("Prius", 13),
new PieChart.Data("Audi A7", 25),
new PieChart.Data("Audi R8", 10),
new PieChart.Data("BMW i8", 22),
new PieChart.Data("Premio", 30));
topVehiclesChart.setData(pieChartData);
topVehiclesChart.setTitle("Top Vehicles");
break;
case 2 :
pieChartData = FXCollections.observableArrayList(
new PieChart.Data("Prius", 73),
new PieChart.Data("Audi A7", 25),
new PieChart.Data("Audi R8", 17),
new PieChart.Data("BMW i8", 45),
new PieChart.Data("Premio", 90));
topVehiclesChart.setData(pieChartData);
break;
case 3 : break;
default : new AlertBuilder("warn","Top Vehicles","Top Vehicle Graph",
"Invalid type of graph !!");
}
}
private ObservableList<PieChart.Data> createData() {
return 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));
}
private void setDrilldownData(final PieChart pie, PieChart.Data data, final String labelPrefix) {
data.getNode().setOnMouseClicked(new EventHandler<MouseEvent>() {
public void handle(MouseEvent t) {
pie.setData(FXCollections.observableArrayList(
new PieChart.Data(labelPrefix + "-1", 7),
new PieChart.Data(labelPrefix + "-2", 2),
new PieChart.Data(labelPrefix + "-3", 5),
new PieChart.Data(labelPrefix + "-4", 3),
new PieChart.Data(labelPrefix + "-5", 2)));
}
});
}
public PieChartSample() {
ObservableList<PieChart.Data> pieChartData = FXCollections.observableArrayList(
new PieChart.Data("Sun", 20),
new PieChart.Data("IBM", 12),
new PieChart.Data("HP", 25),
new PieChart.Data("Dell", 22),
new PieChart.Data("Apple", 30)
);
PieChart chart = new PieChart(pieChartData);
chart.setClockwise(false);
getChildren().add(chart);
}
/**
* 経験値比率
* @param ships 対象艦
*/
private void setRatio(List<Ship> ships) {
Map<TypeGroup, Long> collect = ships.stream()
.collect(Collectors.groupingBy(TypeGroup::toTypeGroup, TreeMap::new,
Collectors.summingLong(this::getExp)));
ObservableList<PieChart.Data> value = FXCollections.observableArrayList();
for (Entry<TypeGroup, Long> data : collect.entrySet()) {
if (data.getKey() != null)
value.add(new PieChart.Data(data.getKey().name(), data.getValue()));
}
this.ratio.setData(value);
}
public void fillPieChart(int months)
{
ArrayList<ArrayList<String>> data = admin.lastMonthsReports(months);
String[] test = {
"Blood Grouping & Rh","Lipid Profile Test","LFT","RFT",
"HIV","CPK","Pathalogy Test",
"Complete Blood Count"
};
ObservableList<PieChart.Data> pieChartData = FXCollections.observableArrayList();
pieChartData.clear();
int tmpSize = test.length;
for(int i = 0; i < tmpSize; i++)
{
pieChartData.add(new PieChart.Data(test[i], Integer.parseInt(data.get(1).get(i))));
}
pieChartData.forEach(data1 ->
data1.nameProperty().bind(
Bindings.concat(
data1.getName(), " (", data1.pieValueProperty(), ")"
)
)
);
labReportPieChart.setData(pieChartData);
ArrayList<Integer> month = new ArrayList<Integer>();
for (int i = 1; i < 13; i++)
{
month.add(i);
}
//reportsCombo.getItems().clear();
//reportsCombo.getItems().addAll(month);
//reportsCombo.setValue(12);
}
@FXML
public void fillPieChart() {
HashMap<String,String> supplierNames = pharmacist.getSupplierNames();
ArrayList<ArrayList<String>> suppliers = pharmacist.getSupplierSummary();
int noOfSuppliers = suppliers.get(0).size();
ObservableList<PieChart.Data> pieChartData = FXCollections.observableArrayList();
for (int i = 0; i < noOfSuppliers; i++)
{
String supplierID = suppliers.get(0).get(i);
int stocks = Integer.parseInt(suppliers.get(1).get(i));
pieChartData.add(new PieChart.Data(supplierNames.get(supplierID), stocks));
}
pieChartData.forEach(data1 ->
data1.nameProperty().bind(
Bindings.concat(
data1.getName(), " (", data1.pieValueProperty().intValue(), ")"
)
)
);
//piechart.setLabelLineLength(20);
piechart.setLegendSide(Side.BOTTOM);
piechart.setLabelsVisible(true);
piechart.setData(pieChartData);
}
@Override public void start(Stage stage) {
stage.setTitle("Imported Fruits");
stage.setWidth(500);
stage.setHeight(500);
ObservableList<PieChart.Data> pieChartData = createData();
final DoughnutChart chart = new DoughnutChart(pieChartData);
chart.setTitle("Imported Fruits");
Scene scene = new Scene(new StackPane(chart));
stage.setScene(scene);
stage.show();
}
public static void addTooltipToData(final PieChart.Data data, final StringProperty label) {
data.nodeProperty().addListener((value, oldNode, newNode) -> {
if (newNode != null) {
Tooltip.install(newNode, createNumberedTooltip(label, data.pieValueProperty()));
}
});
}
private void showErlangMemory() {
ObservableList<PieChart.Data> data = FXCollections.observableArrayList();
showPieChart(data);
ErlangMemoryThread emThread;
emThread = new ErlangMemoryThread(data);
emThread.start();
}
@FXML
private void onStackPie() {
ObservableList<PieChart.Data> data = buildData(chartableProcs(), (p) -> {return p.getStackSize(); });
showPieChart("Process Stack", data);
}
private void initMemoryChart(MemoryInformation memoryInfo) {
pieMemory.setTitle("Total size: " + Utils.humanReadableByteCount(memoryInfo.getPhysicalMemorySize()));
//pieMemory.setTitle("Total size: " + Utils.humanReadableByteCount(5500000012L) + "GB");
// Data of pie chart
ObservableList<PieChart.Data> data = FXCollections.observableArrayList();
data.add(new PieChart.Data("In Use " + Utils.humanReadableByteCount(memoryInfo.getInUseMemorySize()), Utils.humanReadableByteCountNumber(memoryInfo.getInUseMemorySize())));
data.add(new PieChart.Data("Free " + Utils.humanReadableByteCount(memoryInfo.getFreePhysicalMemory()), Utils.humanReadableByteCountNumber(memoryInfo.getFreePhysicalMemory())));
//data.add(new PieChart.Data("In Use", Utils.humanReadableByteCount(3000000012L)));
//data.add(new PieChart.Data("Free", Utils.humanReadableByteCount(2200000012L)));
pieMemory.setData(data);
pieMemory.getData().forEach(d -> {
d.nameProperty().bind(Bindings.concat(d.getName()));
}
);
}
@FXML
private void onHeapPie() {
ObservableList<PieChart.Data> data = buildData(chartableProcs(), (p) -> {return p.getHeapSize(); });
showPieChart("Process Heap", data);
}
@FXML
private void onTotalHeapPie() {
ObservableList<PieChart.Data> data = buildData(chartableProcs(), (p) -> {return p.getTotalHeapSize(); });
showPieChart("Total Heap", data);
}
public ErlangMemoryThread(ObservableList<PieChart.Data> thePieData) {
pieData = thePieData;
setName("Erlang Memory Thread");
setDaemon(true);
}