JasperReports:参数还是字段?
我想知道用字段值而不是参数填充 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我不认为有任何好处。这只是语义上的差异。字段来自数据源,应该放在详细信息带中,该详细信息带将为数据源中的每个元素重复。参数具有唯一的值,对于整个报告来说是全局的。
因此,如果您必须为结果集(或集合的 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.