爲我的應用程序使用jfree圖表(折線圖)...我的圖表在創建時看起來很模糊..我如何獲得高清晰度的圖像。如何提高jfree圖表的質量(分辨率)
我用:ChartUtilities.writeScaledChartAsPNG(baos, chart, 205, 100, 4, 3);
它不工作...請建議我任何想法來做到這一點。
UPDATE 1:
final JFreeChart chart = ChartFactory.createLineChart(
"", // chart title
"", // domain axis label
"", // range axis label
categoryDataset, // data
PlotOrientation.VERTICAL, // orientation
false, // include legend
false, // tooltips
false // urls
);
chart.setBackgroundPaint(Color.WHITE);
final CategoryPlot plot = (CategoryPlot) chart.getPlot();
plot.setBackgroundPaint(Color.WHITE);
plot.setOutlineVisible(false);
plot.setRangeGridlinePaint(Color.white);
final CategoryAxis categoryAxis = plot.getDomainAxis();
categoryAxis.setAxisLineVisible(false);
categoryAxis.setTickMarksVisible(false);
categoryAxis.setMaximumCategoryLabelLines(2);
categoryAxis.setTickLabelFont(ticklabelfont);
final NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();
rangeAxis.setVisible(false);
rangeAxis.setRange(minRange, maxRange);
rangeAxis.setTickUnit(new NumberTickUnit(20));
final LineAndShapeRenderer renderer = (LineAndShapeRenderer) plot.getRenderer();
categoryAxis.setTickLabelPaint(Color.decode("#222222"));
if (lineColorFlag) {
renderer.setSeriesStroke(0, new BasicStroke(1.5f));
} else {
chart.setPadding(new RectangleInsets(0, -8, 0, 0));
renderer.setSeriesStroke(0, new BasicStroke(1.2f));
}
renderer.setBaseShapesVisible(true);
renderer.setBaseShapesFilled(true);
renderer.setSeriesItemLabelsVisible(1, Boolean.TRUE);
Shape circle = new Ellipse2D.Double(-3, -3, 6, 6);
renderer.setSeriesShape(0, circle);
renderer.setSeriesShape(1, null);
renderer.setBaseItemLabelGenerator(new CustomLabelGenerator());
renderer.setItemLabelAnchorOffset(-5);
renderer.setBaseItemLabelsVisible(true);
plot.getRenderer().setSeriesPaint(0, Color.decode("#FEC240"));
renderer.setBaseItemLabelFont(annotationlabelfont);
plot.getRenderer().setSeriesPaint(1, Color.WHITE);
try {
// BufferedImage bi = chart.createBufferedImage(205, 100);
// BufferedImage image = chart.createBufferedImage(205, 100);
// PngEncoder encoder = new PngEncoder(image, false, 0, 9);
// encoder.setDpi(300, 300);
// byte[] data = encoder.pngEncode();
// InputStream in = new ByteArrayInputStream(data);
// BufferedImage bImageFromConvert = ImageIO.read(in);
ByteArrayOutputStream baos = new ByteArrayOutputStream();
ChartUtilities.writeScaledChartAsPNG(baos, chart, 205, 100, 4, 3);
byte[] bi=baos.toByteArray();
InputStream in = new ByteArrayInputStream(bi);
BufferedImage bImageFromConvert = ImageIO.read(in);
PngEncoder pngEncoder=new PngEncoder(bImageFromConvert);
// ChartUtilities.writeScaledChartAsPNG(baos, chart, 205, 100, 2, 2);
ImageIO.write(bImageFromConvert, "png", baos);
byte[] byteArray = baos.toByteArray();
O/P圖像:
請問您可以添加所有相關的代碼嗎? –
我已添加我的代碼@SteffenNieuwenhoven – Hariprasath
爲什麼不使用JavaFX?它有很好的設計圖表,可以更容易地使用。唯一的問題是將您當前的應用程序移植到那裏。這就是爲什麼這個評論只是一個建議,讓你知道JavaFX,以防你不知道它。 –