andrqxa Posted September 5, 2016 Share Posted September 5, 2016 Hi all, Can anybody give right direction in solving such problem. I have query (MySQL) which returned as result table with fields: "year", "month", "day", "hour", "someValue_1", . . . , "someValue_4". My customer wants that I added HTML5 Chart (StackedColumn) to report (I work with Pro-version). And this chart must always have 24 samples (on X-Axis) , but it's problem, because there are some empty values, i.e. we have hour like this 1, 2, 3, 5, 8, 10 My questions are: 1) Which method should I use to add empty rows to table, i.e. if there is not hour number 3, I have to add row which hour = 3 and all values = 0; 2) Can I into scriptlet load ALL values ALL rows(fields) in local variable? And then change it? Best regards, Andrew Link to comment Share on other sites More sharing options...
hozawa Posted September 5, 2016 Share Posted September 5, 2016 I recommend that you create another table which will have empty rows missing in your customer's table. One way to do this is to use Jaspersoft ETL to extract rows from your customer table and to insert into your table. Another method is to create a bean object and insert necessary rows in the bean object and use this bean as your data source instead of jdbc. Link to comment Share on other sites More sharing options...
ajay_1311 Posted September 6, 2016 Share Posted September 6, 2016 Check If you can use UNION QueryE.g.Select year, month, day, hour, someValue_1 from Table1UnionSelect 0, 0, 0,hour,0 from TableStaticHour --Ajay Patil Link to comment Share on other sites More sharing options...
Solution andrqxa Posted September 16, 2016 Author Solution Share Posted September 16, 2016 I have found the solution. May be it will help somebody.In main report created parameter NAME_OF_MY_PARAMETER with type of net.sf.jasperreports.engine.JRDataSourceCreated scriptlet In scriptlet beforeReportInit() method received value of REPOT_CONNECTION parameterConnection conn = (Connection) this.parametersMap.get("REPORT_CONNECTION").getValue();[/code] Run query which I needed and received result (ArrayList in my cause) Processed result and got ArrayList which I needed (i.e. added additional rows)override setData method in scriptletpublic void setData(Map parameters, Map fields, Map variables, JRFillGroup[] groups) { super.setData(parameters, fields, variables, groups); JRFillParameter parameter = (JRFillParameter) parameters.get("NAME_OF_MY_PARAMETER"); parameter.setValue(JRMeasureDataSourceFactory.getDataSource(measures));}[/code]call setData in beforeReportInit method of scriptletIn main report created subreport and as a DataSource of it set parameter NAME_OF_MY_PARAMETERin subreport left its query as empty (or as select 1)added field to subreport which had type and name which I needcreated chart which I needed Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now