更高质量的 JFreeChart 图表

发布于 2024-12-08 00:00:51 字数 164 浏览 0 评论 0原文

我想将使用 JFreeChart 创建的 PNG 图表嵌入到 PDF 文档中。这里的问题是图表的质量很差。我的目标是拥有 300 DPI 的 PNG。我用谷歌搜索了将近一个小时,但找不到解决方案。

有没有办法将 JFreeCharts 生成的图表导出为 300 DPI 的 PNG(或 JPEG)?

I want to embed a PNG of a chart 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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

手长情犹 2024-12-15 00:00:51

另请查看 org.jfree.chart.ChartUtilities#writeScaledChartAsPNG

如果您提供的比例因子为 2,您的图表将以两倍的分辨率呈现。

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.

不乱于心 2024-12-15 00:00:51

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.

滥情哥ㄟ 2024-12-15 00:00:51

您可以使用 XChart 来实现此目的,因为以高分辨率导出图表某些 DPI 是自版本 2.2.0 以来的新功能。代码看起来像这样:

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

免责声明:我是 XChart 的首席开发人员。我最近遇到了和你完全相同的问题。我需要 300 DPI 的图表来制作科学出版物。欢迎反馈!

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!

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文