• Java 报表之JFreeChart(第一讲)


     

    1、利用 JFreeChart 创建垂直柱状报表

     1 package com.wcy.chart.bar;
     2 
     3 import javax.servlet.http.HttpSession;
     4 
     5 import org.jfree.chart.ChartFactory;
     6 import org.jfree.chart.JFreeChart;
     7 import org.jfree.chart.plot.PlotOrientation;
     8 import org.jfree.chart.servlet.ServletUtilities;
     9 import org.jfree.data.category.DefaultCategoryDataset;
    10 
    11 public class BarChart1 {
    12 
    13     public static String genBarChart(HttpSession session) throws Exception {
    14         DefaultCategoryDataset dataset = new DefaultCategoryDataset();
    15         dataset.addValue(510, "深圳", "苹果");
    16         dataset.addValue(320, "深圳", "香蕉");
    17         dataset.addValue(580, "深圳", "橘子");
    18         dataset.addValue(390, "深圳", "梨子");
    19         JFreeChart chart=ChartFactory.createBarChart3D("水果销售统计图", "水果", "销售", dataset,
    20                 PlotOrientation.VERTICAL, true, true, true);
    21         String fileName=ServletUtilities.saveChartAsPNG(chart, 700, 500, null,session);
    22         return fileName;
    23     }
    24 }
     1 <%@page import="com.wcy.chart.bar.BarChart1"%>
     2 <%@ page language="java" contentType="text/html; charset=UTF-8"
     3     pageEncoding="UTF-8"%>
     4 <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
     5 <html>
     6 <head>
     7 <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
     8 <title>Insert title here</title>
     9 </head>
    10 <body>
    11 <%
    12     String fileName = BarChart1.genBarChart(session);
    13 %>
    14 <img src="DisplayChart?filename=<%=fileName %>" width="700" height="500" border="0">
    15 </body>
    16 </html>

    2、利用 JFreeChart 创建横向柱状报表

     1 package com.wcy.chart.bar;
     2 
     3 import javax.servlet.http.HttpSession;
     4 
     5 import org.jfree.chart.ChartFactory;
     6 import org.jfree.chart.JFreeChart;
     7 import org.jfree.chart.plot.PlotOrientation;
     8 import org.jfree.chart.servlet.ServletUtilities;
     9 import org.jfree.data.category.DefaultCategoryDataset;
    10 
    11 public class BarChart2 {
    12 
    13     public static String genBarChart(HttpSession session)throws Exception{
    14         DefaultCategoryDataset dataset = new DefaultCategoryDataset();
    15         dataset.addValue(510, "深圳", "苹果");
    16         dataset.addValue(320, "深圳", "香蕉");
    17         dataset.addValue(580, "深圳", "橘子");
    18         dataset.addValue(390, "深圳", "梨子");
    19         JFreeChart chart = ChartFactory.createBarChart3D("水果销量统计图", "水果", "销售", dataset, PlotOrientation.HORIZONTAL, true,true, true);
    20         String fileName = ServletUtilities.saveChartAsPNG(chart, 700, 500, null, session);
    21         return fileName;
    22     }
    23 }
     1 <%@page import="com.wcy.chart.bar.BarChart2"%>
     2 <%@ page language="java" contentType="text/html; charset=UTF-8"
     3     pageEncoding="UTF-8"%>
     4 <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
     5 <html>
     6 <head>
     7 <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
     8 <title>Insert title here</title>
     9 </head>
    10 <body>
    11 <%
    12     String fileName = BarChart2.genBarChart(session);
    13 %>
    14 <img alt="" src="DisplayChart?filename=<%=fileName %>" width="700" height="500" border="0">
    15 </body>
    16 </html>

     声明:此程序代码本人只是用于学习总结,非原创,如有侵权,联系本人。

  • 相关阅读:
    复杂系统架构设计<1>
    DevExpress Applications<3>
    DevExpress Skins<2>
    DevExpress MVVM<1>
    Unity容器<1>
    spring cloud微服务快速教程之(九) Spring Cloud Alibaba--sentinel-限流、熔断降级
    spring cloud微服务快速教程之(八) Spring Cloud Alibaba--nacos(二)、配置中心
    spring cloud微服务快速教程之(七) Spring Cloud Alibaba--nacos(一)、服务注册发现
    小白的springboot之路(十五)、mybatis的PageHelper分页插件使用
    spring cloud微服务快速教程之(六) 应用监控 spring boot admin
  • 原文地址:https://www.cnblogs.com/wangchaoyuan/p/5972807.html
Copyright © 2020-2023  润新知