You can see an effect on an attached movie.
Just switch on autoranging and you get labels, not fitting in the control's boundaries.
Code:
import java.util.Arrays;
import java.util.Comparator;
import java.util.Random;
import javafx.application.Application;
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import javafx.scene.Scene;
import javafx.scene.chart.BubbleChart;
import javafx.scene.chart.NumberAxis;
import javafx.scene.chart.XYChart;
import javafx.scene.control.ToggleButton;
import javafx.scene.layout.Pane;
import javafx.scene.layout.VBox;
import javafx.scene.text.Font;
import javafx.stage.Stage;
import javafx.util.StringConverter;
public class JavaCharts extends Application {
public static void main(String[] args) {
launch(args);
}
NumberAxis axis1 = new NumberAxis(0, 100, 10);
NumberAxis axis2 = new NumberAxis(0, 100, 10);
BubbleChart chart = new BubbleChart(axis1, axis2);
VBox vb = new VBox();
@Override
public void start(Stage stage) throws Exception {
chart.setTitle("BubbleChart");
chart.setStyle("-fx-border-color: darkgray;");
ObservableList list = FXCollections.observableArrayList();
int max = 100;
int min = 30;
for (int i = 0; i < 30; i++) {
XYChart.Data newData = new XYChart.Data();
newData.setXValue(new Random().nextDouble() * (max - min) + min);
newData.setYValue(new Random().nextDouble() * (max - min) + min);
newData.setExtraValue(new Random().nextDouble() * (max - min) / 4);
list.add(newData);
}
Object[] array = list.toArray();
Arrays.sort(array, new Comparator() {
@Override
public int compare(Object t, Object t1) {
return (int) Math.round(((Double) ((XYChart.Data) t).getXValue()) - ((Double) ((XYChart.Data) t1).getXValue()));
}
});
XYChart.Series serie = new XYChart.Series("serie", FXCollections.observableArrayList(array));
chart.getData().add(serie);
Pane pane = new Pane();
pane.setPrefSize(600, 600);
axis2.setTickLabelFormatter(new ChartsLabelFormatter<Number>());
axis2.setTickLabelFont(new Font("Arial", 20));
axis2.setLowerBound(-0.5437);
ToggleButton tb = new ToggleButton("Auto ranging");
tb.selectedProperty().bindBidirectional(axis2.autoRangingProperty());
pane.setPrefSize(600, 600);
pane.getChildren().add(chart);
vb.getChildren().addAll(pane, tb);
Scene scene = new Scene(vb, 700, 700);
stage.setScene(scene);
stage.show();
}
private static class ChartsLabelFormatter<Number> extends StringConverter<Number> {
@Override
public String toString(Number t) {
return "Form" + t;
}
@Override
public Number fromString(String string) {
throw new UnsupportedOperationException("Not supported yet.");
}
}
}
Just switch on autoranging and you get labels, not fitting in the control's boundaries.
Code:
import java.util.Arrays;
import java.util.Comparator;
import java.util.Random;
import javafx.application.Application;
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import javafx.scene.Scene;
import javafx.scene.chart.BubbleChart;
import javafx.scene.chart.NumberAxis;
import javafx.scene.chart.XYChart;
import javafx.scene.control.ToggleButton;
import javafx.scene.layout.Pane;
import javafx.scene.layout.VBox;
import javafx.scene.text.Font;
import javafx.stage.Stage;
import javafx.util.StringConverter;
public class JavaCharts extends Application {
public static void main(String[] args) {
launch(args);
}
NumberAxis axis1 = new NumberAxis(0, 100, 10);
NumberAxis axis2 = new NumberAxis(0, 100, 10);
BubbleChart chart = new BubbleChart(axis1, axis2);
VBox vb = new VBox();
@Override
public void start(Stage stage) throws Exception {
chart.setTitle("BubbleChart");
chart.setStyle("-fx-border-color: darkgray;");
ObservableList list = FXCollections.observableArrayList();
int max = 100;
int min = 30;
for (int i = 0; i < 30; i++) {
XYChart.Data newData = new XYChart.Data();
newData.setXValue(new Random().nextDouble() * (max - min) + min);
newData.setYValue(new Random().nextDouble() * (max - min) + min);
newData.setExtraValue(new Random().nextDouble() * (max - min) / 4);
list.add(newData);
}
Object[] array = list.toArray();
Arrays.sort(array, new Comparator() {
@Override
public int compare(Object t, Object t1) {
return (int) Math.round(((Double) ((XYChart.Data) t).getXValue()) - ((Double) ((XYChart.Data) t1).getXValue()));
}
});
XYChart.Series serie = new XYChart.Series("serie", FXCollections.observableArrayList(array));
chart.getData().add(serie);
Pane pane = new Pane();
pane.setPrefSize(600, 600);
axis2.setTickLabelFormatter(new ChartsLabelFormatter<Number>());
axis2.setTickLabelFont(new Font("Arial", 20));
axis2.setLowerBound(-0.5437);
ToggleButton tb = new ToggleButton("Auto ranging");
tb.selectedProperty().bindBidirectional(axis2.autoRangingProperty());
pane.setPrefSize(600, 600);
pane.getChildren().add(chart);
vb.getChildren().addAll(pane, tb);
Scene scene = new Scene(vb, 700, 700);
stage.setScene(scene);
stage.show();
}
private static class ChartsLabelFormatter<Number> extends StringConverter<Number> {
@Override
public String toString(Number t) {
return "Form" + t;
}
@Override
public Number fromString(String string) {
throw new UnsupportedOperationException("Not supported yet.");
}
}
}