jFfreechart生成JPG格式图片出现不正常背景色问题

jFreechart版本:1.0.13

 

图片生成代码:

CategoryDataset dataset = DatasetUtilities.createCategoryDataset(rowkeys, columnkeys, data);
		StandardChartTheme standardChartTheme = new StandardChartTheme("CN"); //设置标题字体  
		standardChartTheme.setExtraLargeFont(new Font("DYNASTY", Font.BOLD, 12)); //设置图例的字体
		standardChartTheme.setRegularFont(new Font(SONG, Font.PLAIN, 12)); //设置轴向的字体 
		standardChartTheme.setLargeFont(new Font(SONG, Font.PLAIN, 12)); //应用主题样式 
		ChartFactory.setChartTheme(standardChartTheme);
		JFreeChart chart = ChartFactory.createBarChart("", GENE, NUMVALUE, dataset, PlotOrientation.VERTICAL, showtip, false, false);

BufferedImage bi = chart.createBufferedImage(width, height);

使用上述代码生成JPG的图片将出现不正常的红色背景,而生成PNG图片则每次问题。

 

解决方法:

手动设置imageType为1(即BufferedImage.TYPE_INT_RGB),如下代码:

BufferedImage bi = chart.createBufferedImage(width, height,BufferedImage.TYPE_INT_RGB, null);

 或创建BufferedImage实例时指定imageType为1:

BufferedImage image = new BufferedImage(270, 250, BufferedImage.TYPE_INT_RGB);

你可能感兴趣的:(chart)