Getting value from DB and use it in scriptlet

Jaspersoft Community 'Read-Only' as of July 8, 2022

Transition to New TIBCO Community Just Weeks Away

You can still search, review wiki content, and review discussions in read-only mode. Please email community@tibco.com with questions or issues requiring TIBCO review or response.

I am trying to get a value from a field in a data base and use it in scriptlet in order to make a pie chart in jasperStudio

There are two ways I thought about:

First: create a variable in jasperStudio and assign it with its expression to a field of a data base

Second: get fields value in scriptlet and use it.

But non of this procedures work for me and the value of testVb remains 0.0 and it takes no space in pie chart

The Scriptlet is:

@Override
    public void afterReportInit() throws JRScriptletException {
        Double testVb = new Double(0.0);
        DefaultPieDataset dataset = new DefaultPieDataset();

        //** non of these two bellow lines of codes work for me **//
        // testVb = (Double) this.getVariableValue("vVisual");
         testVb =  (Double) this.getFieldValue("KN_Perzentile");


        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));
    }

and this my 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">
    <property name="com.jaspersoft.studio.data.defaultdataadapter" value="QIDBReport"/>
    <property name="com.jaspersoft.studio.data.sql.tables" value=""/>
    <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"/>
    <variable name="vVisual" class="java.lang.Double" calculation="System">
        <variableExpression><![CDATA[$F{KN_Perzentile}]]></variableExpression>
    </variable>
    <background>
        <band splitType="Stretch"/>
    </background>
    <title>
        <band height="79" splitType="Stretch"/>
    </title>
    <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>
    <summary>
        <band height="42" splitType="Stretch"/>
    </summary>
</jasperReport>

iman.gharib's picture
Joined: Nov 18 2015 - 3:46am
Last seen: 1 year 7 months ago

1 Answer:

I had some problem with my query wich gave me back null. I got the right solution regarding this link:

http://stackoverflow.com/questions/38006907/data-will-not-shown-at-jaspersoft-studio-6-2-2-data-set-dialog

iman.gharib's picture
Joined: Nov 18 2015 - 3:46am
Last seen: 1 year 7 months ago
Feedback
randomness