jsp页面化JFreeChart图

//BarChart3D

<%@ page language="java" import="java.awt.Font,java.awt.Color" pageEncoding="UTF-8"%>
<%@ page import="org.jfree.chart.ChartFactory,
                org.jfree.chart.JFreeChart,
                org.jfree.chart.plot.PlotOrientation,
                org.jfree.chart.servlet.ServletUtilities,
                org.jfree.data.category.CategoryDataset,
                org.jfree.chart.plot.CategoryPlot,
                org.jfree.data.general.DatasetUtilities,
                org.jfree.chart.axis.CategoryAxis,
                org.jfree.chart.axis.ValueAxis,
                org.jfree.chart.renderer.category.BarRenderer3D,
                org.jfree.chart.labels.StandardCategoryItemLabelGenerator,
                org.jfree.chart.axis.AxisLocation,
                org.jfree.chart.renderer.category.CategoryItemRenderer"
                %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <%double[][] data = new double[][]{{672, 766, 223, 540, 126}, {325, 521, 210, 340, 106}, {332, 256, 523, 240, 526}};
  String[] rowsKeys={"苹果","梨子","葡萄"};
  String[] columnKeys={"北京","上海","广州","成都","深圳"};
  CategoryDataset dataset = DatasetUtilities.createCategoryDataset(rowsKeys,columnKeys,data);
  JFreeChart freechart = ChartFactory.createBarChart3D("水果销售量统计图","水果","销量",dataset,PlotOrientation.VERTICAL,true,true,true);
  freechart.setBackgroundPaint(Color.LIGHT_GRAY);
  freechart.getTitle().setPaint(Color.BLUE);
  //1
  CategoryPlot plot = freechart.getCategoryPlot();
  CategoryAxis domainAxis = plot.getDomainAxis();
  //设置距离图片左端距离
  domainAxis.setLowerMargin(0.02);
  //设置距离图片右端距离
  domainAxis.setUpperMargin(0.02);
  plot.setDomainAxis(domainAxis);
 
  //2
  ValueAxis rangeAxis = plot.getRangeAxis();
  //设置最高的一个柱与图片顶端的距离
  rangeAxis.setUpperMargin(0.08);
  //设置最低的一个柱与图片底端的距离
  rangeAxis.setLowerMargin(0.24);
  plot.setRangeAxis(rangeAxis);
 
  //3
  BarRenderer3D bar = new BarRenderer3D();
  bar.setBaseOutlinePaint(Color.BLACK);
  //设置 Wall 的颜色
  bar.setWallPaint(Color.darkGray);
 
  //设置每种水果代表的柱的颜色
  bar.setSeriesPaint(0,new Color(255,0,0));
  bar.setSeriesPaint(1,new Color(0,255,0));
  bar.setSeriesPaint(2,Color.BLUE);
 
  //设置每种水果代表的柱的 Outline 颜色
  bar.setSeriesOutlinePaint(0,Color.BLACK);
  bar.setSeriesOutlinePaint(1,Color.BLACK);
  bar.setSeriesOutlinePaint(2,Color.BLACK);
  //设置每个地区所包含的平行柱的之间距离
  bar.setItemMargin(0.02);
  //显示每个柱的数值,并修改该数值的字体属性
  bar.setItemLabelGenerator(new StandardCategoryItemLabelGenerator());
  bar.setDrawBarOutline(true);
  bar.setIncludeBaseInRange(true);
  bar.setItemLabelFont(new Font("华文新魏",Font.PLAIN,8));
  bar.setItemLabelsVisible(true);
  plot.setRenderer(bar);
 
  plot.setForegroundAlpha(1.00f);
  //设置地区、销量的显示位置
  String filename=ServletUtilities.saveChartAsPNG(freechart,500,320,null,session);
  String grapUrl=request.getContextPath()+"/show?filename=" + filename;%>
 
  <img src="<%=grapUrl%>" width="600" height="400" border="0" usemap="#<%=filename%>">
  <body>
  </body>
</html>

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值