Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8095453

[NumberAxis] tick label formatter is not applied to the existing values.

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Resolved
    • Priority: P4
    • Resolution: Cannot Reproduce
    • Affects Version/s: 7u6
    • Fix Version/s: 8u20
    • Component/s: javafx
    • Environment:

      2.2.0b14

      Description

      You may see it on the attached movie.

      I applied tick label formatter by chosing it from dropDown. It affected by width of new labels. But not by text. Formatter works like this: ((String -> String){ str -> "form" + str }) You may see, how I change upper bound value, and newly appeared labels are affected by that formatter.

      Code:
      import java.util.*;
      import javafx.application.Application;
      import javafx.collections.FXCollections;
      import javafx.collections.ObservableList;
      import javafx.scene.Scene;
      import javafx.scene.chart.LineChart;
      import javafx.scene.chart.NumberAxis;
      import javafx.scene.chart.XYChart;
      import javafx.scene.control.ComboBox;
      import javafx.scene.control.Slider;
      import javafx.scene.layout.Pane;
      import javafx.scene.layout.VBox;
      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);
          LineChart testedLineChart = new LineChart(axis1, axis2);
          VBox vb = new VBox();

          @Override
          public void start(Stage stage) throws Exception {
              testedLineChart.setTitle("LineChart");
              testedLineChart.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);
                  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));

              testedLineChart.getData().add(serie);

              Pane pane = new Pane();
              pane.setPrefSize(600, 600);

              Slider slider = new Slider(0, 1000, 10);
              slider.setPrefWidth(500);
              slider.valueProperty().bindBidirectional(axis2.upperBoundProperty());
              slider.setShowTickLabels(true);
              slider.setShowTickMarks(true);

              List<StringConverter<Number>> temp = new ArrayList<StringConverter<Number>>();
              temp.add(new NumberAxis().getTickLabelFormatter());
              temp.add(new ChartsLabelFormatter<Number>());

              ComboBox cb = new ComboBox();
              cb.getItems().addAll(temp);
              cb.valueProperty().bindBidirectional(axis2.tickLabelFormatterProperty());

              pane.setPrefSize(600, 600);
              pane.getChildren().add(testedLineChart);

              vb.getChildren().addAll(pane, slider, cb);

              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.");
              }
          }
      }

      Chose commonFormatter from the dropDown of the comboBox in the bottom of the stage and after that start to move slider.

        Attachments

          Activity

            People

            Assignee:
            jgiles Jonathan Giles
            Reporter:
            akirov Alexander Kirov (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Dates

              Created:
              Updated:
              Resolved:
              Imported: