CODE:
<%@ page contentType="text/html;charset=GBK"%> <%@ page language="java" pageEncoding="GBK"%> <%@ page import="org.jfree.chart.ChartFactory, org.jfree.chart.JFreeChart, org.jfree.chart.plot.PlotOrientation, org.jfree.chart.servlet.ServletUtilities, org.jfree.data.category.DefaultCategoryDataset, org.jfree.data.category.CategoryDataset, org.jfree.data.general.DatasetUtilities, java.awt.Color, java.awt.Font, org.jfree.chart.block.*, org.jfree.chart.plot.*, org.jfree.chart.axis.*, org.jfree.chart.title.LegendTitle, org.jfree.data.general.DefaultPieDataset, org.jfree.data.general.PieDataset, org.jfree.ui.*, org.jfree.chart.labels.StandardPieSectionLabelGenerator, java.text.DecimalFormat, java.text.NumberFormat, org.jfree.chart.title.TextTitle "%> <% DefaultCategoryDataset dataset = new DefaultCategoryDataset(); dataset.addValue(610, "广州", "猪肉"); dataset.addValue(220, "广州", "牛肉"); dataset.addValue(530, "广州", "鸡肉"); dataset.addValue(340, "广州", "鱼肉"); JFreeChart chart = ChartFactory.createBarChart3D("肉类销量统计图", "肉类", "销量", dataset, PlotOrientation.VERTICAL, false, false, false); chart.getTitle().setFont(new Font("隶书", Font.ITALIC, 20));//设置标题 chart.setBackgroundPaint(Color.white); //设定背景色为白色 CategoryPlot categoryPlot=chart.getCategoryPlot();//获得 plot,用于设置显示特性 categoryPlot.setBackgroundPaint(Color.WHITE); categoryPlot.setDomainGridlinePaint(Color.BLACK);//分类轴网格线条颜色 categoryPlot.setDomainGridlinesVisible(true); categoryPlot.setRangeGridlinePaint(Color.GREEN);//数据轴网格线条颜色 //图表的字体设置 CategoryAxis domainAxis=categoryPlot.getDomainAxis(); //水平底部列表 domainAxis.setLabelFont(new Font("楷体",Font.BOLD,14)); //X轴标题 domainAxis.setTickLabelFont(new Font("宋体",Font.BOLD,12)); //x轴下标 ValueAxis rangeAxis=categoryPlot.getRangeAxis();//获取柱状 rangeAxis.setLabelFont(new Font("楷体",Font.BOLD,14)); //Y轴标题 /* categoryplot.setBackgroundPaint(Color.lightGray); //设定图表数据显示部分背景色 categoryplot.setDomainGridlinePaint(Color.white); //横坐标网格线白色 categoryplot.setDomainGridlinesVisible(true); //可见 categoryplot.setRangeGridlinePaint(Color.white); //纵坐标网格线白色 */ String filename = ServletUtilities.saveChartAsPNG(chart, 500, 300, null, session); String graphURL = request.getContextPath() + "/servlet/DisplayChart?filename=" + filename; %> <img src="<%= graphURL %>"width=500 height=300 border=0 usemap="#<%= filename %>">
运行结果: