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>

  • 相关阅读:
    k8s采坑记
    [dotnet] 封装一个同时支持密码/安全密钥认证的SFTP下载器,简单易用。
    亲测可用,iptables实现NAT转发。
    【转】干货,Kubernetes中的Source Ip机制。
    k8s实践
    干货!分享一款windows下的磁盘分析神器。
    干货,不小心执行了rm -f,除了跑路,如何恢复?
    Java8函数式编程
    搭建git服务器
    Python3安装
  • 原文地址:https://www.cnblogs.com/luoxiaolei/p/5080766.html
Copyright © 2011-2022 走看看