You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何在Jasper报表的<jr:table>中实现符合条件的数据椭圆高亮显示

Got it, let's tackle this problem step by step. You want to highlight numeric values with an ellipse when a condition (y < X) is met, using a <jr:table> component with JRBeanCollectionDataSource. Here's how you can make it work:

Step-by-Step Implementation

1. Add an Ellipse Shape to Your Detail Cell

You'll need to add an <ellipse> element to your detail cell—this will be the highlight shape. Place it before your text field (Jasper draws elements in XML order, so the text will sit on top of the ellipse).

2. Set Up Conditional Display for the Ellipse

Use printWhenExpression on the ellipse to only render it when your y < X condition is true. Adjust the condition to match your actual field names or threshold values.

3. Sync Sizing & Style

Make sure the ellipse's x, y, width, and height match your text field exactly so it perfectly wraps the value. You can also add optional styling (fill color, border color) to make the highlight stand out.

Modified Code Snippet

Here's your updated detail cell code with all the necessary changes:

<jr:detailCell style="table_TD" height="20" rowSpan="1">
    <!-- Ellipse highlight: only shows when y < X -->
    <ellipse>
        <reportElement 
            mode="Opaque" 
            x="0" 
            y="0" 
            width="250" 
            height="19" 
            uuid="your-custom-uuid-here">
            <!-- Replace with your actual condition: e.g., $F{yourNumericField} < 50 or $F{yourNumericField} < $P{thresholdValue} -->
            <printWhenExpression><![CDATA[$F{targetNumericField} < $P{thresholdX}]]></printWhenExpression>
            <!-- Optional: Customize highlight appearance -->
            <property name="net.sf.jasperreports.shape.fill.color" value="#FFFFCC"/> <!-- Light yellow fill -->
            <property name="net.sf.jasperreports.shape.border.color" value="#FFCC00"/> <!-- Gold border -->
        </reportElement>
    </ellipse>

    <!-- Your existing text field (now sits on top of the ellipse) -->
    <textField>
        <reportElement 
            mode="Transparent" 
            x="0" 
            y="0" 
            width="250" 
            height="19" 
            isRemoveLineWhenBlank="true" 
            uuid="a457d366-5e92-4588-be11-182d164a8db3">
            <printWhenExpression><![CDATA[!($F{country}.isEmpty())]]></printWhenExpression>
        </reportElement>
        <!-- Don't forget this line to display your numeric value! -->
        <textFieldExpression><![CDATA[$F{targetNumericField}]]></textFieldExpression>
    </textField>
</jr:detailCell>
Key Notes
  • Z-Order Check: If the ellipse covers your text, double-check that the ellipse comes before the text field in the XML—Jasper renders later elements on top.
  • Condition Customization: Swap $F{targetNumericField} and $P{thresholdX} with your actual field/parameter names. For a fixed threshold, use something like $F{targetNumericField} < 100.
  • Style Flexibility: Remove the fill color property or set mode="Transparent" on the ellipse if you only want a border instead of a filled shape.

内容的提问来源于stack exchange,提问作者kallada

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.06 06:52:19