首页 > Web开发 > 详细

JasperReport Chart使用

时间:2021-06-14 17:33:21      阅读:14      评论:0      收藏:0      [点我收藏+]

1、在tmeplate4_charts模板里创建Field

技术分享图片

 

 

 grade属性, 类型为java.lang.String

 

 

 

 nums属性 类型为java.lang.Long

 

2、在右边的Basic Element中拖拽Chart

技术分享图片

 

 

 这里我们选择Pie Chart

 

技术分享图片

 

 

 点击完成。

最终的模板如下图所示

技术分享图片

 

 

 

 

创建StudentCount 类

public class StudentCount {

    private String grade;
    private  Long nums;

    public String getGrade() {
        return grade;
    }

    public void setGrade(String grade) {
        this.grade = grade;
    }

    public Long getNums() {
        return nums;
    }

    public void setNums(Long nums) {
        this.nums = nums;
    }
}

  

java代码

@GetMapping("/jasper4_chart")
    public void jasper4_chart( HttpServletResponse response)
            throws Exception {
        HashMap<String, Object> parameters = new HashMap<String, Object>();

        List<StudentCount> studentList = new ArrayList<>();
        for (int i = 1; i <= 6; i++) {
            Random random = new Random();
            int count = ((Double) (random.nextDouble() * 10)).intValue();
            StudentCount s1 = new StudentCount();
            s1.setGrade("grade"+ i );
            s1.setNums(i * 20L + count);
            studentList.add(s1);
        }
        String templatePath = "templates/template4_charts.jasper";
        JasperReportUtil.exportToPdf(templatePath, parameters, studentList, response);
    }

  

 

最终展示的pdf效果如下图

技术分享图片

 

JasperReport Chart使用

原文:https://www.cnblogs.com/linlf03/p/14882320.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!