jfreechart 柱状图

<%@ page language="java" pageEncoding="UTF-8"%>
<!-- 导入jfreechart 包 -->
<%@ page import="org.jfree.chart.ChartFactory, 
	java.awt.Color,
	java.awt.Font,
	org.jfree.chart.JFreeChart,
	org.jfree.chart.axis.ValueAxis,
	org.jfree.chart.labels.StandardCategoryItemLabelGenerator,
	org.jfree.chart.plot.CategoryPlot,
	org.jfree.chart.plot.PlotOrientation,
	org.jfree.chart.renderer.category.*,
	org.jfree.chart.servlet.ServletUtilities,
	org.jfree.data.category.CategoryDataset,
	org.jfree.data.category.DefaultCategoryDataset,
	java.util.ArrayList" 
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <title>信息分类统计</title>
  </head>
  
  <body>
<%
CategoryDataset dataset; 
String category="江苏营业厅";
dataset=this.getDataSet();

String title=category+"业务缴费总金额统计"; 
JFreeChart chart = ChartFactory.createBarChart(title,  
"城市", 
"业务缴费总金额", 
dataset, 
PlotOrientation.VERTICAL, 
true, 
false, 
false); 	

String filename = ServletUtilities.saveChartAsPNG(chart,750, 350, null, session); 
String graphURL = request.getContextPath() + "/servlet/DisplayChart?filename=" + filename;
%> 
<P ALIGN="CENTER"> 
<img src="<%=graphURL%>" border=0 usemap="#<%= filename %>">
</P>


<%!
	public static CategoryDataset getDataSet() 
	{ 
	DefaultCategoryDataset dataset = new DefaultCategoryDataset();
		for(int i=0;i<3;i++)
			{
				dataset.addValue(10,"nj", "");
				dataset.addValue(30,"zj", "");
				dataset.addValue(30,"xz", "");
				dataset.addValue(20,"sz", "");
			}
		return dataset; 
	}
%>
  </body>
</html>


web.xml

<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.5" 
	xmlns="http://java.sun.com/xml/ns/javaee" 
	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
	xsi:schemaLocation="http://java.sun.com/xml/ns/javaee 
	http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
  <welcome-file-list>
    <welcome-file>index.jsp</welcome-file>
  </welcome-file-list>
  
  <servlet>
  <servlet-name>DisplayChart</servlet-name> 
  <servlet-class>org.jfree.chart.servlet.DisplayChart</servlet-class> 
  </servlet>
  <servlet>
    <description>This is the description of my J2EE component</description>
    <display-name>This is the display name of my J2EE component</display-name>
    <servlet-name>JasperServlet</servlet-name>
    <servlet-class>com.jasper.JasperServlet</servlet-class>
  </servlet>

  
 <servlet-mapping>
  <servlet-name>DisplayChart</servlet-name> 
  <url-pattern>/servlet/DisplayChart</url-pattern> 
  </servlet-mapping>
  <servlet-mapping>
    <servlet-name>JasperServlet</servlet-name>
    <url-pattern>/servlet/JasperServlet</url-pattern>
  </servlet-mapping>
  <!-- ireport -->
   <servlet>
       <servlet-name>ImageServlet</servlet-name>
       <servlet-class>net.sf.jasperreports.j2ee.servlets.ImageServlet</servlet-class>
   </servlet>

   <servlet-mapping>
       <servlet-name>ImageServlet</servlet-name>
       <url-pattern>/servlets/image</url-pattern>
   </servlet-mapping>

  
</web-app>

你可能感兴趣的:(java,Web,xml,servlet,jfreechart)