views:

312

answers:

1

I have a line chart generated from a SQL, I need the data to be plotted in different colors based on the value. For example: Green color for positive values and Red color for negative values.

I have added the jrxml content,

<parameter name="conName" isForPrompting="true" class="java.lang.String"/>
<parameter name="conId" isForPrompting="true" class="java.lang.String"/>
<parameter name="orgId" isForPrompting="true" class="java.lang.String"/>
<parameter name="chartName" isForPrompting="true" class="java.lang.String"/>
<parameter name="sql" isForPrompting="true" class="java.lang.String"/>
<parameter name="unit" isForPrompting="true" class="java.lang.String"/>
<parameter name="indicatorName" isForPrompting="true" class="java.lang.String"/>
<queryString><![CDATA[$P!{sql}]]></queryString>

<field name="INDICATOR_NAME" class="java.lang.String"/>
<field name="UNIT_OF_MEASURE" class="java.lang.String"/>
<field name="E_DATE" class="java.lang.String"/>
<field name="CALCULATED_VALUE" class="java.math.BigDecimal"/>
<field name="FLAG_VALUE" class="java.math.BigDecimal"/>


    <summary>
        <band height="350"  isSplitAllowed="true" >
            <lineChart>
                <chart  hyperlinkTarget="Self" >
                <reportElement
                    x="0"
                    y="0"
                    width="500"
                    height="350"
                    key="element-1"/>
                <box></box>
                    <chartTitle color="#000000" >
                <font fontName="Trebuchet MS" pdfFontName="Helvetica" size="11" isBold="true" isItalic="false" isUnderline="false" isStrikeThrough="false" isPdfEmbedded="false" pdfEncoding="Cp1252"/>
                            <titleExpression><![CDATA[str($P{chartName})+" - "+$P{indicatorName}]]></titleExpression>
                </chartTitle>
                    <chartLegend textColor="#000000" backgroundColor="#FFFFFF" >
                </chartLegend>
                </chart>
                <categoryDataset>
                    <dataset >
                    </dataset>
                    <categorySeries>
                        <seriesExpression><![CDATA[$F{INDICATOR_NAME}]]></seriesExpression>
                        <categoryExpression><![CDATA[$F{E_DATE}]]></categoryExpression>
                        <valueExpression><![CDATA[$F{CALCULATED_VALUE}]]></valueExpression>
            <itemHyperlink   hyperlinkType="Reference">
                    <hyperlinkTooltipExpression><![CDATA[""+$F{CALCULATED_VALUE}]]></hyperlinkTooltipExpression>
            </itemHyperlink>
                    </categorySeries>
                </categoryDataset>
                <linePlot >
                    <plot />
                    <categoryAxisFormat>
                        <axisFormat >
                        </axisFormat>
                    </categoryAxisFormat>
                <valueAxisLabelExpression><![CDATA[$P{unit}]]></valueAxisLabelExpression>
                    <valueAxisFormat>
                        <axisFormat >
                            <labelFont>
                <font fontName="Trebuchet MS" pdfFontName="Helvetica" size="10" isBold="true" isItalic="false" isUnderline="false" isStrikeThrough="false" isPdfEmbedded="false" pdfEncoding="Cp1252"/>
                            </labelFont>
                            <tickLabelFont>
                            </tickLabelFont>
                        </axisFormat>
                    </valueAxisFormat>
                </linePlot>
            </lineChart>
        </band>
    </summary>

A: 

Hi,

You may need to use the customizer class to set the colors. You can access the data in the customizer class. You might need to put the conditions for the data and assign the colors to the lines.

Multiplexer