我怎样才能避免"分手"用折线图-JasperReport?

时间:2017-12-18 15:22:19

标签: jasper-reports linechart

我正在使用Jaspersoft Studio版本6.3.0.final和JasperReports Library版本6.3.0。我创建了一个包含不同系列和类别值的折线图。我的问题是,当绘制图表时,我观察到如果对于一个类别没有特定系列的值,则换行并且该行从下一个数据点再次开始。

无论如何,我们可以连接特定系列中的所有点,以便它是一条连续的单行而不是虚线和点?

我把一张图片作为我得到和想要做的一个例子,把我的.jrxml文件作为折线图。

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 个答案:

答案 0 :(得分:0)

我实现了我想要的东西,我刚刚改变了图表的类型,现在我正在使用“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>