简单柱状图

<%@ page contentType="text/html;charset=GBK"%>

<%@ page import="org.jfree.chart.ChartFactory, org.jfree.chart.plot.CategoryPlot,java.awt.Font,org.jfree.chart.plot.PlotOrientation, org.jfree.chart.title.TextTitle,org.jfree.chart.axis.CategoryAxis,  org.jfree.chart.axis.NumberAxis,       org.jfree.chart.JFreeChart,           org.jfree.chart.plot.PlotOrientation,          org.jfree.chart.servlet.ServletUtilities,      org.jfree.data.category.DefaultCategoryDataset"%>
<%
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);
  //图表标题以及副标题乱码                  
Font font = new Font("宋体", Font.BOLD, 16);
TextTitle title = new TextTitle("肉类销量统计图", font);
//副标题
TextTitle subtitle = new TextTitle("副标题", new Font("黑体", Font.BOLD, 12));

chart.addSubtitle(subtitle);

chart.setTitle(title); //标题    
         
CategoryPlot plot = chart.getCategoryPlot();               
NumberAxis numberaxis = (NumberAxis) plot.getRangeAxis();

CategoryAxis domainAxis = plot.getDomainAxis(); 
  //X轴乱码
domainAxis.setTickLabelFont(new Font("sans-serif", Font.PLAIN, 11));
domainAxis.setLabelFont(new Font("宋体", Font.PLAIN, 12));
//Y轴乱码            
numberaxis.setTickLabelFont(new Font("sans-serif", Font.PLAIN, 12)); 
numberaxis.setLabelFont(new Font("黑体", Font.PLAIN, 12)); 
     //图表底部乱码
    // chart.getLegend().setItemFont(new Font("宋体", Font.PLAIN, 12));        
String filename = ServletUtilities.saveChartAsPNG(chart, 500, 300, null, session);
String graphURL = request.getContextPath() + "/DisplayChart?filename=" + filename;
%>
<img src="<%= graphURL %>"width=500 height=300 border=0 usemap="#<%= filename %>"/>

你可能感兴趣的:(html,servlet,jfreechart)