Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to realize X-axis dynamic grouping according to parameters in BIRT Statistical Chart

2025-02-02 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/01 Report--

BIRT statistics chart how to achieve X-axis dynamic grouping according to parameters, many novices are not very clear about this, in order to help you solve this problem, the following editor will explain in detail for you, people with this need can come to learn, I hope you can gain something.

Report tools are generally good at dealing with data with consistent rules, but dynamic operations with inconsistent conditions are difficult to achieve in reports. The common practice is to write a segment program to prepare the data source, and then send it to BIRT to draw, instead of directly processing the data and drawing in BIRT.

For example, to deal with such a scenario: the X axis of the statistical graph takes time as the scale and displays different values according to the conditions of different parameters. Statistics for 1 hour, one every 5 minutes, to generate 12, expected results:

Statistics 1 day, one per hour, to generate 24, the expected results:

Count one item a week, one a day, generate 7 items, and expect results:

You can use the API provided by BIRT to modify the scale of the X axis, and the code should look something like this:

...

Function beforeGeneration (chart, icsc)

{/ / 01 hour 02 day 03 week

Var type = icsc.getExternalContext () .getScriptable () .getParameterValue ("type")

...

Var xAxisArray = chart.getAxes ()

XAxisArray [0] .setCategoryAxis (false)

If (type=='01') {

XAxisArray [0] .getScale () .setUnit (xAxisArray [0] .getScale () .getUnit () .MINUTES_LITERAL)

XAxisArray [0] .getScale () .setStep (5)

} else if (type=='02') {

XAxisArray [0] .getScale () .setUnit (xAxisArray [0] .getScale () .getUnit () .HOURS_LITERAL)

XAxisArray [0] .getScale () .setStep (1)

} else {

XAxisArray [0] .getScale () .setUnit (xAxisArray [0] .getScale () .getUnit () .DAYS_LITERAL)

XAxisArray [0] .getScale () .setStep (1)

}

}

...

It is recommended to use the aggregator, whose rich set operations can easily complete this kind of calculation, which is much shorter than the code written by Java. For example, similar calculations can be written in the aggregator (assuming that the data table is tv, where the occurrence time is listed as t and the statistical value is listed as v):

A

B

one

= []

two

If (type== "hour")

> A1: 12. (elapse@s (now (),-5: 60))

three

Else if (type== "day")

> A1: 24. (elapse@s (now (),-60: 60))

four

Else if (type== "week")

> A1 / 7. (elapse (now (),-~))

five

= A1. (demo.query ("select sum (v) from tv where t >? and t

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report