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

如何让BIRT中的图表宽度拉伸至页面全屏?

How to Stretch BIRT Charts to Full Page Width in HTML Reports

I've run into this exact stubborn issue with BIRT's HTML report output before—those inline styles on the embed tag always override the class-based styles! Let's walk through the most reliable fixes to get your chart stretching to full page width:

1. Disable Fixed Size in Chart Properties

First, let's stop BIRT from generating those hardcoded fixed pt values in the first place:

  • Open your report in the BIRT Designer, and select the chart component
  • In the Properties panel, navigate to the Size or Formatting section (location varies slightly by BIRT version)
  • Uncheck the option labeled "Use Fixed Size" (or similar wording)
  • Confirm your chart's width and height are set to 100%, and double-check the parent container (like a Grid cell or Table row) also has its width set to 100%—containers can restrict the chart even if the chart itself is set to full width.

2. Use onRender Script to Remove Inline Styles

If the UI settings don't fully override the inline styles, we can use BIRT's built-in scripting to modify the DOM on render:

  • Select either the chart element itself or the report's Master Page
  • Switch to the Script tab, and choose the onRender event (this triggers when generating HTML output)
  • Add this JavaScript snippet to strip out the fixed inline styles:
// Target the chart's embed element—use class selector for reliability
var chartEmbed = document.querySelector('.style_5');
if (chartEmbed) {
    // Remove the fixed width/height properties
    chartEmbed.style.removeProperty('width');
    chartEmbed.style.removeProperty('height');
    // Force full dimensions
    chartEmbed.style.width = '100%';
    chartEmbed.style.height = '100%';
}

If your chart's embed ID is dynamic (like __bookmark_3 in your example), using the class selector .style_5 is more reliable than targeting a specific ID.

3. Modify BIRT's HTML Export Template CSS

BIRT tends to strip !important from user-imported CSS, but adding the rule directly to BIRT's core export templates avoids this issue:

  • Locate your BIRT installation directory, then navigate to webcontent/birt/report (or frameset depending on your setup)
  • Open the report.css file (or the main CSS template for HTML exports)
  • Add this rule at the bottom:
embed.style_5 {
    width: 100% !important;
    height: 100% !important;
}
  • Restart your BIRT report server, then re-export your report—this template-level CSS will take precedence over the inline styles.

One quick check to rule out other issues: make sure your report's page width is set to match the full viewport (in Master Page properties), and there's no padding/margins on the body or parent containers that are shrinking the available space.

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.05.29 09:01:40