柱状图

<%@ 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.JFreeChart,
org.jfree.chart.plot.PlotOrientation,
org.jfree.chart.servlet.ServletUtilities,
org.jfree.data.category.CategoryDataset,
org.jfree.data.general.DatasetUtilities"%>

<%
double[][] data = new double[][] {{1310}, {720}, {1130}, {440}};
String[] rowKeys = {"猪肉", "牛肉","鸡肉", "鱼肉"};
String[] columnKeys = {""};
CategoryDataset dataset = DatasetUtilities.createCategoryDataset(rowKeys, columnKeys, data);
JFreeChart chart = ChartFactory.createBarChart3D("广州肉类销量统计图", "肉类",
"销量",
dataset,
PlotOrientation.VERTICAL,
true,
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)