List of usage examples for javafx.scene.chart PieChart getData
public final ObservableList<Data> getData()
From source file:Main.java
@Override public void start(Stage primaryStage) { PieChart pieChart = new PieChart(); pieChart.setData(getChartData());/* w ww. j av a 2 s . com*/ System.out.println(pieChart.getData()); pieChart.setTitle("Title"); pieChart.setLegendSide(Side.LEFT); pieChart.setClockwise(false); pieChart.setLabelsVisible(false); StackPane root = new StackPane(); root.getChildren().add(pieChart); primaryStage.setScene(new Scene(root, 300, 250)); primaryStage.show(); }
From source file:Main.java
@Override public void start(Stage stage) { Scene scene = new Scene(new Group()); stage.setTitle("Imported Fruits"); stage.setWidth(500);//from ww w.j ava2 s .c om 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); //scene.getStylesheets().add("piechartsample/Chart.css"); stage.show(); }
From source file:com.jscriptive.moneyfx.ui.chart.ChartFrame.java
/** * This method is invoked when the "by category" button has been toggled * * @param actionEvent//from ww w . ja va 2 s.co m */ public void byCategoryToggled(ActionEvent actionEvent) { final PieChart pieChart = new PieChart(); pieChart.setTitle("Transaction balance by categories"); pieChart.setLegendSide(LEFT); chartFrame.setCenter(pieChart); ToggleButton toggle = (ToggleButton) actionEvent.getTarget(); if (toggle.isSelected()) { Service<Void> service = new Service<Void>() { @Override protected Task<Void> createTask() { return new Task<Void>() { @Override protected Void call() throws Exception { ValueRange<LocalDate> period = getTransactionOpRange(accountCombo.getValue(), yearCombo.getValue()); if (period.isEmpty()) { return null; } Platform.runLater(() -> pieChart.setTitle(format("%s for transactions from %s until %s", pieChart.getTitle(), period.from().format(DATE_FORMATTER), period.to().format(DATE_FORMATTER)))); categoryRepository.findAll().stream() .sorted((c1, c2) -> c1.getName().compareTo(c2.getName())).forEach(category -> { List<Transaction> found = (accountCombo.getValue() == ALL_ACCOUNTS) ? transactionRepository.findByCategory(category) : transactionRepository.findByAccountAndCategory( accountCombo.getValue(), category); if (INTEGER_ZERO.compareTo(yearCombo.getValue()) < 0) { found = found.stream().filter( trx -> yearCombo.getValue().equals(trx.getDtOp().getYear())) .sorted((t1, t2) -> t1.getDtOp().compareTo(t2.getDtOp())) .collect(toList()); } List<Transaction> transactions = new ArrayList<>(found.size()); transactions.addAll(found); Platform.runLater(() -> { double value = getSum(transactions); String name = format("%s [%s]", category.getName(), CurrencyFormat.getInstance().format(value)); PieChart.Data data = new PieChart.Data(name, value); pieChart.getData().add(data); data.getNode().addEventHandler(MOUSE_CLICKED, event -> handleCategoryChartMouseClickEvent( (accountCombo.getValue() == ALL_ACCOUNTS) ? null : accountCombo.getValue(), category, yearCombo.getValue(), event)); }); }); return null; } }; } }; service.start(); } }
From source file:View.Visualize.java
public void getPieChartData(Integer nameColumn, Integer valueColumn, Table table, PieChart pieChart, Label lbl, Boolean newSeries, Boolean rowCounter) { data.clear();/*from ww w.j a v a 2s .com*/ if (!newSeries) { pieChart.getData().clear(); } addDataFromTable(table, nameColumn, valueColumn, rowCounter); data.entrySet().stream().map(entry -> new PieChart.Data(entry.getKey(), entry.getValue())) .forEach(pieChart.getData()::add); for (PieChart.Data d : pieChart.getData()) { //deretter legger vi animasjon p piecharten.. d.getNode().setOnMouseClicked(new mouseHooverAnimationPieChart.MouseHoverAnimation(d, pieChart)); final Node n = d.getNode(); Tooltip tooltip = new Tooltip(); String toolTipText = "Value : " + d.getPieValue(); tooltip.setText(toolTipText); Tooltip.install(n, tooltip); n.setOnMouseEntered(new EventHandler<MouseEvent>() { @Override public void handle(MouseEvent e) { n.setEffect(glow); } }); n.setOnMouseExited(new EventHandler<MouseEvent>() { @Override public void handle(MouseEvent e) { n.setEffect(null); } }); final ContextMenu contextMenu = new ContextMenu(); MenuItem changeColor = new MenuItem("Change Color"); MenuItem delete = new MenuItem("Standard color"); ColorPicker cp = new ColorPicker(); changeColor.setGraphic(cp); contextMenu.getItems().addAll(changeColor, delete); d.getNode().setOnMouseClicked(new EventHandler<MouseEvent>() { @Override public void handle(MouseEvent t) { if (t.getButton() == MouseButton.SECONDARY) { delete.setOnAction(new EventHandler() { public void handle(Event t) { d.getNode().setStyle(""); } }); cp.setValue(null); cp.setOnAction(new EventHandler() { public void handle(Event t) { String hex1 = "#" + Integer.toHexString(cp.getValue().hashCode()); d.getNode().setStyle("-fx-background-color: " + hex1 + ";"); } }); contextMenu.show(d.getNode(), t.getScreenX(), t.getScreenY()); } } }); } }