Last active
August 29, 2015 14:16
-
-
Save angelicalleite/0b67fb27b118433f84ff to your computer and use it in GitHub Desktop.
JavaFX - Info valores gráficos de barrra
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package br.com.fapce.ugb.util; | |
import javafx.application.Platform; | |
import javafx.beans.value.ObservableValue; | |
import javafx.geometry.Bounds; | |
import javafx.scene.Group; | |
import javafx.scene.Node; | |
import javafx.scene.Parent; | |
import javafx.scene.chart.XYChart; | |
import javafx.scene.text.Text; | |
/** | |
* Auxilia na exibição dos valores no gráficos de barras | |
* | |
* @author Angelica | |
*/ | |
public class GraficoBarra { | |
private GraficoBarra() { | |
} | |
/** | |
* Informar a barra do grafico no qual deseja exibir os valores | |
*/ | |
public static void infoBar(XYChart.Data< String, Number> data) { | |
Node node = data.getNode(); | |
Text texto = new Text(data.getYValue() + ""); | |
texto.setStyle("-fx-fill: #888; -fx-font-size: 11px;"); | |
node.parentProperty().addListener((ObservableValue<? extends Parent> obs, Parent old, Parent parent) -> { | |
Platform.runLater(() -> { | |
if (parent != null) { | |
Group parentGroup = (Group) parent; | |
parentGroup.getChildren().add(texto); | |
} | |
}); | |
}); | |
node.boundsInParentProperty().addListener((ObservableValue<? extends Bounds> obs, Bounds old, Bounds bounds) -> { | |
texto.setLayoutX(Math.round(bounds.getMinX() + bounds.getWidth() / 2 - texto.prefWidth(- 1) / 2)); | |
texto.setLayoutY(Math.round(bounds.getMinY() - texto.prefHeight(- 1) * 0.5)); | |
}); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Muito interessante.