如何以编程方式呈现来自 JFreeChart 的图像文件。我有 ChartPanel 的代码:是否可以直接呈现图像 - 而无需创建 AWT/GUI 组件?
val chart = .. // Imagine code to generate chart data here..
val panel = new ChartPanel(chart)
panel.renderToImage() // replace this with logic to save image file
最佳答案
使用 ChartUtilities
之一方法,例如 writeChartAsJPEG()
或 writeChartAsPNG()
,可以写入 java.io.OutputStream
;或 saveChartAsJPEG()
或 saveChartAsPNG()
,可以写入 java.io.File
。可以看到一些例子here和 here .例如,
ChartUtilities.saveChartAsPNG(new File("chart.png"), chart, width, height);
您还想研究 headless 模式,提到了 here .
关于java - 从 JFreeChart 到图像文件的服务器端/非交互式图表渲染,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31641004/