开发者

Higher Quality of JFreeChart charts

开发者 https://www.devze.com 2023-04-10 01:46 出处:网络
I want to embed a PNG of a c开发者_如何学JAVAhart which I created with JFreeChart into a PDF document. The problem here is, that the quality of the chart is very poor. My goal is to have PNGs with 300

I want to embed a PNG of a c开发者_如何学JAVAhart which I created with JFreeChart into a PDF document. The problem here is, that the quality of the chart is very poor. My goal is to have PNGs with 300 DPI. I googled for almost an hour now but I could not find a solution.

Is there a way to export the generated charts from JFreeCharts as a PNG (or a JPEG) with 300 DPI?


Also take a look at org.jfree.chart.ChartUtilities#writeScaledChartAsPNG

If you provide a scale factor of 2, your chart will be rendered at twice the resolution.


Since version 1.4, JFreeChart uses the png encoder provided by ImageIO. As an alternative , you might look at com.keypoint.PngEncoder, which includes setDpi(), et al. See also org.jfree.chart.encoders.SunPNGEncoderAdapter and org.jfree.chart.encoders.KeypointPNGEncoderAdapter.


You could use XChart for this, as exporting Charts in high-res at a certain DPI is a new feature since version 2.2.0. The code would look something like this:

double[] xData = new double[] { 0.0, 1.0, 2.0 };
double[] yData = new double[] { 2.0, 1.0, 0.0 };

// Create Chart
Chart chart = QuickChart.getChart("Sample Chart", "X", "Y", "y(x)", xData, yData);

// Show it
new SwingWrapper(chart).displayChart();

// Save it
BitmapEncoder.savePNG(chart, "./Sample_Chart.png"); // default 72 DPI
BitmapEncoder.savePNGWithDPI(chart, "./Sample_Chart_300_DPI.png", 300);

Disclaimer: I'm the lead developer of XChart. I recently faced the exact same problem as you. I needed charts at 300 DPI for a scientific publication. Feedback is welcome!

0

精彩评论

暂无评论...
验证码 换一张
取 消