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

Use WritableImage to create an image of BarChart, sometimes show a wrong order.

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Incomplete
    • Icon: P4 P4
    • None
    • None
    • javafx
    • windows7 32

      Use WritableImage to create an image of BarChart, sometimes show a wrong order.

      private BarChart<Number, String> itemBar = new BarChart<Number, String>(xAxis, yAxis);
      private final XYChart.Series<Number, String> itemDate = new XYChart.Series<Number, String>();
      itemDate.getData().add(listData);
      itemBar.getData().addAll(itemDate);
      group.getChildren().add(itemBar);

      Group arChart = group;
      InspectUtil.saveImage(arChart, path, IMAGE_WIDTH, IMAGE_HEIGHT);

      // This method is used for creating bar images.
      // I think it has a bug , the list data of this charter has an DESC order ,but the images created are sometimes showing a wrong order(neither DESC nor ASC order).
         public static void saveImage(Node node, String filePath, int width, int height)
          {
              Scene scene = new Scene((Parent)node, width, height);
              scene.getStylesheets().add(EdeskResourceUtil.getCssPath(InspectUtil.class.getClassLoader(),
                  InspectionUiConst.CSS_STYLE));
              WritableImage wim = new WritableImage(width, height);
              scene.snapshot(wim);
              File file = new File(filePath);
              try
              {
                  ImageIO.write(SwingFXUtils.fromFXImage(wim, null), "png", file);
              }
              catch (IOException e)
              {
                  log.error(e);
              }
          }

      //Data of the itemBar above has a comparator like below,I debuged this , the data list order is right before creating the image, it's very strange that the images created are sometimes showing a wrong order.
      private List<ProblemStatistics> getSortedProblems()
          {
              List<ProblemStatistics> result = new ArrayList<ProblemStatistics>(problems.values());
              Collections.sort(result, new Comparator<ProblemStatistics>()
              {
                  @Override
                  public int compare(ProblemStatistics o1, ProblemStatistics o2)
                  {
                      return o2.getTotal() - o1.getTotal();
                  }
              });
              return result;
          }

            kcr Kevin Rushforth
            swangjfx Slash Wang (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported: