コード例 #1
0
  @Override
  public void initialize(URL arg0, ResourceBundle arg1) {
    days.bind(viewModel.daysProperty());
    targetLineSeries.dataProperty().bind(viewModel.targetLineDataProperty());
    loggedHoursSeries.dataProperty().bind(viewModel.loggedHoursDataProperty());
    burndownSeries.dataProperty().bind(viewModel.burndownDataProperty());

    burndownChart.getData().addAll(targetLineSeries, loggedHoursSeries, burndownSeries);
    burndownChart.getXAxis().setAutoRanging(true);

    // style
    burndownChart.setLegendVisible(false);
    burndownChart.setAnimated(false);

    yAxis.setMinorTickVisible(false);

    exportHyperlink.setOnAction(
        event -> {
          burndownChart.snapshot(
              snapshotResult -> {
                WritableImage image = snapshotResult.getImage();
                // https://community.oracle.com/thread/2450090?tstart=0
                final FileChooser fileChooser = new FileChooser();
                fileChooser
                    .getExtensionFilters()
                    .addAll(
                        new FileChooser.ExtensionFilter("PNG Files", "*.png"),
                        new FileChooser.ExtensionFilter("All Files", "*"));
                String organisationFilename =
                    viewModel.organisationProperty().get().getSaveLocation().getName();
                fileChooser.setInitialFileName(
                    organisationFilename.substring(0, organisationFilename.lastIndexOf('.'))
                        + ".png");
                File file = fileChooser.showSaveDialog(burndownChart.getScene().getWindow());
                try {
                  if (file != null) {
                    ImageIO.write(SwingFXUtils.fromFXImage(image, null), "png", file);
                  }
                } catch (Exception e) {
                  // TODO Auto-generated catch block
                  e.printStackTrace();
                }
                return null;
              },
              null,
              null);
        });
  }