柱状图

<%@ 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 %>"/>
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值