使用Apache POI在Excel中创建折线图
在代码中导入Graphics2D类,并将其实例化为graphics对象。修改代码如下:
import java.awt.*;
import java.awt.image.BufferedImage;
// ...
public class ExcelChartExample03 {
public static void main(String[] args) {
try {
// ...
// 创建折线图
// ...
// 设置字体
// ...
// 绘制图表
chart.plot(data);
// 绘制图表到图片
BufferedImage image = new BufferedImage(800, 600, BufferedImage.TYPE_INT_RGB);
Graphics2D graphics = image.createGraphics(); // 修改此行
chart.getCTChart().getPlotArea().getRadarChartArray();
chart.plot(data);
// 保存图片文件
ImageIO.write(image, "png", new File("折线图.png"));
// ...
} catch (IOException e) {
e.printStackTrace();
}
}
}
这样就可以解决找不到graphics符号的问题了。
原文地址: http://www.cveoy.top/t/topic/f4mv 著作权归作者所有。请勿转载和采集!