【问题标题】:How can I avoid "line breaking up" with line chart-JasperReport?如何使用折线图 JasperReport 避免“断线”?
【发布时间】:2017-12-18 15:22:18
【问题描述】:

我正在使用 Jaspersoft Studio 版本 6.3.0.final 和 JasperReports 库版本 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>

【问题讨论】:

  • 我们能否提供一些您正在测试的样本数据?对于病变 d,我猜您只有 1 个值,对于其他我需要查看您正在使用的值。
  • 嗨,Petter,我只是使用一些虚拟数据来测试我的折线图,我使用 TableModel 提供来自 eclipse 的数据,其列名如下:columnNames = new String[] { "Lesion", "TimePoints", "LongAxis" } 所以如果你想测试它,你可以通过提供一个“net.sf.jasperreports.engine.data.JRTableModelDataSource”来使用你自己的数据
  • 传递您正在使用的虚拟数据,创建一个minimal reproducible example,对于喜欢回答测试的任何人来说都更快。

标签: jasper-reports linechart


【解决方案1】:

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-12-09
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多