Jasper报告折线图类别表达式相同的值仅打印一次 [英] Jasper report Line chart Category expression same value is printed only once

查看:57
本文介绍了Jasper报告折线图类别表达式相同的值仅打印一次的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Jasper报告折线图.在该折线图中,类别表达式相同的值仅打印一次.

I am using Jasper report line chart. In that line chart Category expression same value is printed only once.

在此,将线名称"中的线名称"列指定为线形图中的类别表达式".不打印冗余值. 仅打印唯一名称. 我想要我的所有名字,即使它是同一个名字.如何解决此问题?

Here, In Thread name column is specified as Category expression in Line chart. Redundant values are not printed. Only the unique names are printed. I want all my names, even if it's same name. How can fix this issue ?

推荐答案

您必须将打印为类别标签的String值包装到满足唯一性约束的对象中.您必须创建一个实现Comparable接口的java类,因为只有不相等的对象才作为单独的类别值打印.以下代码显示了如何实现此类:

You have to wrap your String value which is printed as the category label into an object which fulfills the uniqueness constraint. You have to create a java class which implements the Comparable interface, because only Objects which are not equal are printed as a separate category value. The following code shows how such a class can be implemented:

public class UniqueCategoryLabel implements Comparable<UniqueCategoryLabel> {

    private Double id;
    private String value;

    public UniqueCategoryLabel(String value, Double id) {
        this.value = value;
        this.id = id;
    }

    @Override
    public int compareTo(UniqueCategoryLabel v) {
        return this.id.compareTo(v.id);
    }

    @Override
    public boolean equals(Object v) {
        return v instanceof UniqueCategoryLabel && this.id.equals(((UniqueCategoryLabel) v).id);
    }

    @Override
    public int hashCode() {
        return this.id.hashCode();
    }

    @Override
    public String toString() {
        return value;
    }
}

您可以通过使用不同的ID创建UniqueCategoryLabel实例来提供唯一性,因为equals方法检查比较对象的ID是否相同.图表本身的标签是通过使用提供的对象的toString()方法创建的,因此您的toString()方法应返回要打印为标签的String.在报表中,您用于图表的字段必须是UniqueCategoryLabel类型,而不是String类型,这应该可以解决所有问题.

You can provide uniqueness by creating instances of UniqueCategoryLabel using different ids because the equals method checks if the ids of the compared objects are the same. The labels of the chart themselves are created by using the toString() method of the provided object so your toString() method should return the String which you want to print as a label. In your report the field you use for the chart has to be of the type UniqueCategoryLabel instead of String and that should do all the magic.

这篇关于Jasper报告折线图类别表达式相同的值仅打印一次的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆