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;
}
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;
}