zoukankan      html  css  js  c++  java
  • [二]JFreeChart实践一

    生成一张简单的图片

    java代码:

    package com.lxl.chart;

    import javax.servlet.http.HttpSession;

    import org.jfree.chart.ChartFactory;
    import org.jfree.chart.JFreeChart;
    import org.jfree.chart.plot.PlotOrientation;
    import org.jfree.chart.servlet.ServletUtilities;
    import org.jfree.data.category.DefaultCategoryDataset;

    public class ChartDemo {

    public static String getChartName(HttpSession session) throws Exception {
    DefaultCategoryDataset dataset = new DefaultCategoryDataset();
    dataset.addValue(200, "包头", "茄子");
    dataset.addValue(300, "包头", "辣椒");
    dataset.addValue(400, "包头", "皇冠");
    dataset.addValue(500, "包头", "苹果");
    JFreeChart chart = ChartFactory.createBarChart3D("蔬菜价格表", "", "", dataset, PlotOrientation.VERTICAL, true, true,
    true);
    String chartName = ServletUtilities.saveChartAsPNG(chart, 700, 500,null, session);
    return chartName;
    }
    }

    web.xml

    <servlet>
    <servlet-name>DisplayChart</servlet-name>
    <servlet-class>org.jfree.chart.servlet.DisplayChart</servlet-class>
    </servlet>
    <servlet-mapping>
    <servlet-name>DisplayChart</servlet-name>
    <url-pattern>/DisplayChart</url-pattern>
    </servlet-mapping>

    jsp页面:

    <%@page import="com.lxl.chart.ChartDemo"%>
    <%@ page language="java" contentType="text/html; charset=utf-8"
    pageEncoding="utf-8"%>
    <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
    <title>Insert title here</title>
    </head>
    <%
    String name = ChartDemo.getChartName(session);
    System.out.println(name);
    %>
    <body>
    <img src="DisplayChart?filename=<%=name%>" width="700" height="500" border="0">
    </body>
    </html>

  • 相关阅读:
    代码格式化[转]
    ASP.NET错误大杂烩
    Web考勤管理系统 .net 2005 开发
    Ftp 类
    c#中Split等分割字符串的几种方法
    强大的firebug 使用 介绍
    一页面多个文本框回车提交不同事件问题解决
    Ajax电子书下载 发现的好东东贴上了
    编程技术书籍[转]
    推荐下权威的《IT十年经典书系列》1打
  • 原文地址:https://www.cnblogs.com/luoxiaolei/p/5080766.html
Copyright © 2011-2022 走看看