1
votes

I am using Jaspersoft Studio version 6.3.0.final with JasperReports Library version 6.3.0 . I'm creating a Line chart with different series and category values. My question is that, when the graph is plotted, I observed that if for one category there are no values for a particular series, the line breaks and the line starts again from the next data point.

Is there anyway in which we can connect ALL the points in a particular series, so that it will be one continuous single line instead of broken lines and dots ?

I put an image as an example of what I get and I want to do and my .jrxml file for the line chart.

line chart example

<?xml version="1.0" encoding="UTF-8"?>
<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="chart_subreport" pageWidth="842" pageHeight="595" columnWidth="842" leftMargin="0" rightMargin="0" topMargin="10" bottomMargin="10"> 
<style name="table 1_TH" mode="Opaque" backcolor="#646464" forecolor="#FFFFFF" >
    <box>
        <pen lineColor="#969696" lineWidth="1.0"/>
    </box>
</style>    

<field name="TimePoints" class="java.util.Date"/>
<field name="LongAxis" class="java.lang.Double"/>
<field name="Lesion" class="java.lang.String"/>

<detail>
 <band height="400" >
                <printWhenExpression><![CDATA[$V{REPORT_COUNT}==1]]></printWhenExpression>                    
        <lineChart>
            <chart>
                <reportElement  style="table 1_TH" x="10" y="0" width="800" height="400"/>                  
                <chartTitle>
                    <titleExpression><![CDATA["Lesion's evolution"]]></titleExpression>
                </chartTitle>                                                       
            </chart>                
            <categoryDataset>
                <categorySeries>
                <!-- This is the lesions you want to see on charts-->
                    <seriesExpression><![CDATA[$F{Lesion}]]></seriesExpression>
                    <!--You can change the format date here -->
                    <categoryExpression><![CDATA[(new SimpleDateFormat("MMM d, yyyy")).format($F{TimePoints})]]></categoryExpression>
                    <valueExpression><![CDATA[$F{LongAxis}]]></valueExpression>
                </categorySeries>
            </categoryDataset>                                          
                <linePlot isShowLines="true">
                <plot backcolor="#323232"  />
                <categoryAxisFormat>
                    <axisFormat/>
                </categoryAxisFormat>
                <valueAxisFormat>
                  <axisFormat >
                    <labelFont>
                        <font fontName="Arial" size="10"/>
                    </labelFont>
                </axisFormat>
                </valueAxisFormat>
            </linePlot>             
        </lineChart>    
    </band>
</detail>
</jasperReport>
1
Can we have some sample data that you are testing with also?, for lesion d I guess you have only 1 value, for the others I would need to see the values you are using. - Petter Friberg
Hi Petter, I'm just using some dummies data in order to test my line charts, I provide the data from eclipse by using a TableModel with a column name like : columnNames = new String[] { "Lesion", "TimePoints", "LongAxis" } so if you want to test it you can use your own data by providing a "net.sf.jasperreports.engine.data.JRTableModelDataSource" - Mathieu_n
Pass the dummy data that you are using, create a minimal reproducible example and it's much quicker for anyone who likes to answer to test. - Petter Friberg

1 Answers

0
votes

I achieved to get what I want, I've just changed the type of the chart, now I'm using "timeSeriesChart".

<style name="table 1_TH" mode="Opaque" backcolor="#646464" forecolor="#FFFFFF" >
    <box>
        <pen lineColor="#969696" lineWidth="1.0"/>
    </box>
    </style>    
<queryString>
    <![CDATA[]]>
</queryString>

<field name="TimePoints" class="java.util.Date"/>
<field name="LongAxis" class="java.lang.Double"/>
<field name="Lesion" class="java.lang.String"/>
<field name ="nbInstance" class="java.lang.Integer"/>

<detail>
 <band height="400" >
                <printWhenExpression><![CDATA[$V{REPORT_COUNT}==$F{nbInstance}]]></printWhenExpression>               
        <timeSeriesChart>
            <chart>
                <reportElement  style="table 1_TH" x="10" y="0" width="800" height="400"/>                  
                <chartTitle>
                    <titleExpression><![CDATA["Lesion's evolution"]]></titleExpression>
                </chartTitle>                                                       
            </chart>            

            <timeSeriesDataset>

                <timeSeries>
                    <seriesExpression><![CDATA[$F{Lesion}]]></seriesExpression>
                    <timePeriodExpression> <![CDATA[$F{TimePoints}]]></timePeriodExpression>
                        <valueExpression><![CDATA[$F{LongAxis}]]></valueExpression>
                </timeSeries>
            </timeSeriesDataset>                
                <timeSeriesPlot >
                <plot backcolor="#323232"  />
                <timeAxisLabelExpression/>                  
                <timeAxisFormat>
                    <axisFormat/>
                </timeAxisFormat>
                <valueAxisLabelExpression/>
                <valueAxisFormat>
                    <axisFormat/>
                </valueAxisFormat>
            </timeSeriesPlot>               
        </timeSeriesChart>  
    </band>
</detail>