create bar chart with expression as values - charts

I usually create chart with Passing map object from Java code and in iReport using sub data set I create the chart.
Now I need to create a bar chart from calculated values of other fields of same report. For example one of the text box calculated value is
new java.lang.Double((Double.valueOf( $P{REPORT_PARAMETERS_MAP}.get("budget_labour_cost").toString()).doubleValue())
+ (Double.valueOf( $P{REPORT_PARAMETERS_MAP}.get("budget_ico_cost").toString()).doubleValue())
+ (Double.valueOf( $P{REPORT_PARAMETERS_MAP}.get("budget_subcon_cost").toString()).doubleValue())
+ (Double.valueOf( $P{REPORT_PARAMETERS_MAP}.get("budget_oth_purchase_cost").toString()).doubleValue())
)
I need to use the result of the expression in one bar of bar chart.

You can still use a dataset; simply collect the results of the text fields in a variable (type list or map), then create a new datasource from this for your dataset.
The variable might use an expression similar to
$V{variable}.add() ? $V{variable} : $V{variable}
Calculation type "Nothing".

Related

Grafana+InfluxDB: show series based on value of custom variable

Using Grafana+InfluxDB, is it possible to show a series based upon the value of a custom variable?
I tried using AND "$variable"="value", ie AND "true"="true" but InfluxDB was interpreting it as a field and not just a boolean expression.

iReport sum of two measures

I'm having problem with JasperReports report by getting sum of two fields.
I have created so far variables that holds fields "TareWeight" variable that is casting values from double to float
new Float($F{EquipmentTareWeightKg})
"CargoWt" variable that is casting from string to float, etc...
Float.parseFloat($F{UfvFlexString03})+Float.parseFloat($F{UfvFlexString04})
So now I have two variables which I can manipulate with.
The problem starts when I wish to do a "recap" using crosstab. I have setup two groups that is done with wizard, and added another in crosstab. (please refer to the printscreen below)
And now, I have created under measures SumOf Tare that is using variable TareWt, and SumOfCargoWt that is using variable CargoWt.
I have tried to create another Measure SumOfGrossWt that would do a sum of variables TareWt + CargoWt but I have got some nonsense values.
I have tried to do another approach by creating variable GrossWt that would basically do exact the same thing as previous attempt
$V{Tare}+$V{CargoWt}
or use an variable: GrossWt
$V{Tare}+$V{CargoWt} or new Float($F{EquipmentTareWeightKg})+(Float.parseFloat($F{UfvFlexString03})+Float.parseFloat($F{UfvFlexString04}))
None of these actually worked: (Sum should be done by "Sum Of Tare"+ "Sum of CargoWt" = "Sum of GrossWt") plese refer to the second picture.
Here is a complete jrxml code/file:
jrxml file
save it as *.jrxml
Can please someone help me find a solution? how can I sum those two measure fields and get correct values?
Since CargoWt field had some null values in database, addition float value with null is equal to null, so the only value which was displayed on report are the one that had values for CargoWt, all others with null value were "ignored".

Jaspersoft iReport Can we do subtotals in a list component?

I just wish to know if it is possible to do subtotals in a list component? If so, is it like using a variable and putting the reset type as 'Group' and putting the expression?
There are many limitations of List component (calculations, return values, headers and footers, ...).
See section "13.1.3 List Component Issues" in ireport-ultimate-guide.
Try to use subreport instead list. It is more suited for computation on a subset of data
Yes it is possible.
First you create a variable in the dataset then open variable properties, set calculation sum
Set variable expression which field you want to sum from list component (like $F{paidAmount}) and save
Create a variable in the main report
Open report XML source then go at position in list component and assign value from dataset to main variable like this way
<returnValue fromVariable="sumOfPayment"toVariable="mainSumOfPayment"/>
Example :
<datasetRun subDataset="CreditorList" uuid="6aebc237-1aa2-47db-9435-8b133cef2b31">
<dataSourceExpression><![CDATA[$F{invoices}]]></dataSourceExpression>
<returnValue fromVariable="sumOfPayment" toVariable="mainSumOfPayment"/>
</datasetRun>
then drag the mail variable to the possible you what to show sum that list component field out side of list .and open the variable properties panel and must set Evaluation Time -Report

jasperreports bar charts calculation

I am trying to generate report using iReports. I have to calculate percentage of certain data the expression for which is " new Double( $F{stock}.doubleValue() / $V{stock_SUM}.doubleValue() ) " . this is working correctly when i put the data in columns in the detail band
but when i am using the same expression ("new Double( $F{stock}.doubleValue() / $V{stock_SUM}.doubleValue() ) *100" for percentage ) for my bar graph in the summary this is not giving me correct results.
is there any property which does the same work in bar charts as evaluation time "Auto" does for an expression.if not then how can we achieve correct percentage calculation in barcharts. i have tried changing the evaluation time to report for the chart but that also didn't work.
What is Your datasource? If it is SQL query I suggest prepering the needed data in it and use it in Your chars.
To calculate stock_SUM without rewriting too much, You can use window function. :)

JasperReports customize series labels based on a value other than the Category value

I have a JasperReport with a line chart that I need to display labels on, but I want them to display conditionally for each data point. I've created the customizer class to actually display the value, but I want to use a different field than the value field to decide if it should display or not.
Basically in my DataSet I have 3 fields:
Date: (Category Axis)
Value: (Value Axis)
PrintValue: Boolean field
I want to print the Value in the label only when PrintValue=true
One solution would be to override one of the methods implemented by JRDefaultScriptlet in a scriptlet class, then set the value of "PrintValue" in any manner you desire. Then in your chart dataset you should be able to reference $V{PRINTVALUE} as an operand.
I'm going to assume your using iReport for your report design.
Open your report in iReport and click the report name (Top most node in the report Inspector)
Set the Scriplet class to your package name and class, e.g., org.company.scriptlets.MyChartClass
Declare your report variable in iReport. In this case "PRINTVALUE" would be the variable name.
Create a java class that overrides a scriplet method, like beforeDetailEval, e.g.,:
#Override
public void beforeDetailEval() throws JRScriptletException {
super.beforeDetailEval();
...
this.setVariableValue("PRINTVALUE", true);
}
Since you want to display the category label conditionally for each tick mark, you'll probably need to use a Map of key/val pairs. key would be category label, value would be true/false for "PRINTVALUE". Note I did NOT illustrate this in the sample code above but its entirely possible. Just declare your report variable as a Map, e.g., HashMap<String, Boolean> hm.
You'll need to add your new scriplet class to the Classpath in iReport.
Hope this helps or at least gets you started.