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 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:

    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 =
                    "Pie Chart 3D Demo 1",

        PiePlot3D plot = (PiePlot3D) chart.getPlot();
        plot.setNoDataMessage("No data to display");

        /*   */
        this.setVariableValue("Pie", new JCommonDrawableRenderer(chart));

and this my jrxml:

<jasperReport xmlns="" xmlns:xsi="" xsi:schemaLocation="" name="JFreeReport" pageWidth="595" pageHeight="842" columnWidth="555" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20" uuid="1edc4d15-06d0-46cf-8d57-179fd0bed566">
    <property name="" value="QIDBReport"/>
    <property name="" value=""/>
    <scriptlet name="BoxPlotScript" class="testProjektIman.toc.JFreeChartScriptlet"/>
        <![CDATA[select KN_Perzentile  from  "Kennzahl"  where  KN_ID = 215 and KN_RefWert1 = 8.3]]>
    <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">
        <band splitType="Stretch"/>
        <band height="79" splitType="Stretch"/>
        <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"/>
        <band height="42" splitType="Stretch"/>

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:

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