首页>代码>jfreechart生成柱状图>/jfreechart生成柱状图/src/com/test/ChartGraphics.java
package com.test;

import java.io.*;
import com.sun.image.codec.jpeg.*;
import java.awt.image.*;
import java.awt.*;

public class ChartGraphics {
	 BufferedImage image;
	 public void createImage(String fileLocation) {
		 try {
			 FileOutputStream fos = new FileOutputStream(fileLocation);
			 BufferedOutputStream bos = new BufferedOutputStream(fos);
			 JPEGImageEncoder encoder = JPEGCodec.createJPEGEncoder(bos);
			 encoder.encode(image);
			 bos.close();
		}catch(Exception e) {
			System.out.println(e);
		}
	 }

	 public void graphicsGeneration(int h1,int h2,int h3,int h4,int h5) {

		final int X=10;
		int imageWidth = 300;//图片的宽度
		int imageHeight = 300;//图片的高度
		int columnWidth=30;//柱的宽度
		int columnHeight=200;//柱的最大高度
		
		ChartGraphics chartGraphics = new ChartGraphics();
		chartGraphics.image = new BufferedImage(imageWidth, imageHeight, BufferedImage.TYPE_INT_RGB);
		Graphics graphics = chartGraphics.image.getGraphics();
		graphics.setColor(Color.white);
		graphics.fillRect(0,0,imageWidth,imageHeight);
		graphics.setColor(Color.red);
		graphics.drawRect(X+1*columnWidth, columnHeight-h1, columnWidth, h1);
		graphics.drawRect(X+2*columnWidth, columnHeight-h2, columnWidth, h2);
		graphics.drawRect(X+3*columnWidth, columnHeight-h3, columnWidth, h3);
		graphics.drawRect(X+4*columnWidth, columnHeight-h4, columnWidth, h4);
		graphics.drawRect(X+5*columnWidth, columnHeight-h5, columnWidth, h5);
		chartGraphics.createImage("D:\\temp\\chart.jpg");
	}
} 
最近下载更多
hefei100  LV2 2019年7月16日
NextOne  LV2 2018年8月25日
364550246  LV15 2018年6月10日
a569497437  LV2 2018年5月7日
jiemozi  LV2 2018年3月5日
15996932533  LV1 2018年2月22日
puhuiling  LV9 2017年12月23日
sunnyH  LV1 2017年12月8日
wxsuperwx  LV17 2017年12月2日
lintaotao  LV3 2017年9月13日
最近浏览更多
fesfefe  LV13 2023年11月1日
189676630  LV4 2023年4月19日
tangjj7260  LV18 2021年10月26日
嘉琪拉  LV2 2021年8月31日
heshiyang  LV1 2021年7月11日
我寄愁心  LV8 2021年6月22日
zhaojialiang  LV7 2021年5月14日
江权盛  LV2 2020年12月28日
chenghao4u  LV8 2020年11月25日
鸡毛飞上天  LV3 2020年6月1日
顶部 客服 微信二维码 底部
>扫描二维码关注最代码为好友扫描二维码关注最代码为好友