最近在csdn上面,乱转时看到很有用的东西,利用jfreechart来实现很多复杂图形的效果,
转载的网址:http://www.java2000.net/f30
下面是几个简单的例子:
<%@page language="java" pageEncoding="UTF-8"%> <%@page import="org.jfree.data.category.*,org.jfree.chart.*,org.jfree.chart.plot.*"%> <% out.clearBuffer(); response.setContentType("image/jpeg"); DefaultCategoryDataset dataset=new DefaultCategoryDataset(); dataset.addValue(610,"taian","test1"); dataset.addValue(540,"taian","test2"); dataset.addValue(320,"taian","test3"); dataset.addValue(370,"taian","test4"); dataset.addValue(130,"taian","test5"); JFreeChart chart=ChartFactory.createBarChart("BiangJi","xiaoliang","roulei",dataset,PlotOrientation.VERTICAL,false,false,false); java.io.OutputStream os=response.getOutputStream(); javax.imageio.ImageIO.write(chart.createBufferedImage(500,300),"JPEG",os); os.flush(); os.close(); %>
import org.jfree.chart.ChartFactory; import org.jfree.chart.ChartFrame; import org.jfree.chart.JFreeChart; import org.jfree.data.general.DefaultPieDataset; public class First { public static void main(String[] args) { DefaultPieDataset data=new DefaultPieDataset(); data.setValue("Catagory 1",43.2); data.setValue("Catagory 2",27.9); data.setValue("Catagory 3",79.5); JFreeChart chart=ChartFactory.createPieChart("Sample Pie Chart",data,true,true,false); ChartFrame frame=new ChartFrame("First",chart); frame.pack(); frame.setVisible(true); } }