JasperReports:参数还是字段?

发布于 2024-12-19 10:03:40 字数 1147 浏览 0 评论 0原文

我想知道用字段值而不是参数填充 JasperReport 是否有任何性能优势(或其他优势)。

例如,假设我想用 10 个饼图切片填充饼图。

将饼图的表达式设置为:

JRDesignExpression key = new JRDesignExpression("$F{PieSlice}.key");
JRDesignExpression label = new JRDesignExpression("$F{PieSlice}.label");
JRDesignExpression value = new JRDesignExpression("$F{PieSlice}.value");

...与此相反:

Map<String,String> params = new HashMap<String,String>();
params.put("pie-slice-key-01", "foo");
params.put("pie-slice-label-01", "Foo");
params.put("pie-slice-value-01", .25);
// ... etc.

JasperPrint print = JasperFillManager.fill(jasperDesign, params);

// ...

JRDesignExpression key = new JRDesignExpression("$P{pie-slice-key-01}");
JRDesignExpression label = new JRDesignExpression("$P{pie-slice-label-01}");
JRDesignExpression value = new JRDesignExpression("$P{pie-slice-value-01}");

JRDesignExpression key = new JRDesignExpression("$P{pie-slice-key-02}");
JRDesignExpression label = new JRDesignExpression("$P{pie-slice-label-02}");
JRDesignExpression value = new JRDesignExpression("$P{pie-slice-value-02}");

// ...etc.

提前致谢!

I was wondering if there are any performance benefits (or other benefits) to filling a JasperReport with fields values instead of parameters.

For instance, say I want to populate a pie chart with 10 pie slices.

What benefits - if any - are there to setting the pie's expressions to:

JRDesignExpression key = new JRDesignExpression("$F{PieSlice}.key");
JRDesignExpression label = new JRDesignExpression("$F{PieSlice}.label");
JRDesignExpression value = new JRDesignExpression("$F{PieSlice}.value");

...as opposed to this:

Map<String,String> params = new HashMap<String,String>();
params.put("pie-slice-key-01", "foo");
params.put("pie-slice-label-01", "Foo");
params.put("pie-slice-value-01", .25);
// ... etc.

JasperPrint print = JasperFillManager.fill(jasperDesign, params);

// ...

JRDesignExpression key = new JRDesignExpression("$P{pie-slice-key-01}");
JRDesignExpression label = new JRDesignExpression("$P{pie-slice-label-01}");
JRDesignExpression value = new JRDesignExpression("$P{pie-slice-value-01}");

JRDesignExpression key = new JRDesignExpression("$P{pie-slice-key-02}");
JRDesignExpression label = new JRDesignExpression("$P{pie-slice-label-02}");
JRDesignExpression value = new JRDesignExpression("$P{pie-slice-value-02}");

// ...etc.

Thanks in advance!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

老旧海报 2024-12-26 10:03:40

我不认为有任何好处。这只是语义上的差异。字段来自数据源,应该放在详细信息带中,该详细信息带将为数据源中的每个元素重复。参数具有唯一的值,对于整个报告来说是全局的。

因此,如果您必须为结果集(或集合的 bean)的每一行重复饼图,请使用字段。如果您的报告中只有一张全局饼图,请使用参数。

I don't think there is any benefit. It's just a semantic difference. A field comes from the data source, and is supposed to be put in the details band, which will be repeated for every element in the data source. A parameter has a unique value, global to the whole report.

So, if you must repeat the pie chart for every row of a resultset (or bean of a collection), use fields. If you just have one global pie chart in your report, use parameters.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文