I have faced suddenly the following issues with Jaspersoft Studio data set dialog:
First: After running the first query select KN_Perzentile from "Kennzahl" where KN_ID = 215 and KN_RefWert1 = 8.3 and clicking the refresh preview data the Studio shows that 2 fields are read (which should be one in fact as I tested the query against DB), but the data will not shown at all!
Second: Running any other query there encounters an error, saying that the field KN_Perzentile is not found! This field is not asked in the second query at all!
Both queries are tested against Database and correct. I have these problems only on one project.
The variable vVisual should read the value from the data base.And the java class which is in build path should read his variable and use it for creating the chart. But the data will not be added to the chart. I guess that is because jasper does not read the KN_Perzentile.
This is the chart with Visual Basic = 0 after genarating:
Here is the jrxml:
<jasperReport xmlns="http://jasperreports.sourceforge.net/jasperreports" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://jasperreports.sourceforge.net/jasperreports http://jasperreports.sourceforge.net/xsd/jasperreport.xsd" name="JFreeReport" pageWidth="595" pageHeight="842" columnWidth="555" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20" uuid="1edc4d15-06d0-46cf-8d57-179fd0bed566">
<scriptlet name="BoxPlotScript" class="testProjektIman.toc.JFreeChartScriptlet"/>
<queryString>
<![CDATA[select KN_Perzentile from "Kennzahl" where KN_ID = 215 and KN_RefWert1 = 8.3
]]>
</queryString>
<field name="KN_Perzentile" class="java.lang.Double"/>
<variable name="Pie" class="net.sf.jasperreports.engine.JRRenderable" calculation="System">
<variableExpression><![CDATA[$V{Pie}]]></variableExpression>
<initialValueExpression><![CDATA[$V{Pie}]]></initialValueExpression>
</variable>
<variable name="vVisual" class="java.lang.Double" calculation="First">
<variableExpression><![CDATA[$F{KN_Perzentile}]]></variableExpression>
<initialValueExpression><![CDATA[$F{KN_Perzentile}]]> </initialValueExpression>
</variable>
<detail>
<band height="290" splitType="Stretch">
<image scaleImage="Clip" hAlign="Center">
<reportElement x="60" y="50" width="440" height="215" uuid="60c9de91-e7ad-4ffb-81fd-109a381532b6"/>
<imageExpression><![CDATA[$V{Pie}]]></imageExpression>
</image>
</band>
</detail>
</jasperReport>
Java Class:
public class JFreeChartScriptlet extends JRDefaultScriptlet
{
@Override
public void afterReportInit() throws JRScriptletException {
Double testVb = 0.0;
DefaultPieDataset dataset = new DefaultPieDataset();
testVb = (Double) this.getVariableValue("vVisual");
dataset.setValue("Java", new Double(43.2));
dataset.setValue("Visual Basic", testVb);
dataset.setValue("C/C++", new Double(17.5));
dataset.setValue("PHP", new Double(32.5));
dataset.setValue("Perl", new Double(1.0));
JFreeChart chart =
ChartFactory.createPieChart3D(
"Pie Chart 3D Demo 1",
dataset,
true,
true,
false);
PiePlot3D plot = (PiePlot3D) chart.getPlot();
plot.setStartAngle(290);
plot.setDirection(Rotation.CLOCKWISE);
plot.setForegroundAlpha(0.5f);
plot.setNoDataMessage("No data to display");
this.setVariableValue("Pie", new JCommonDrawableRenderer(chart));
}
}