Jump to content
We've recently updated our Privacy Statement, available here ×

Chart Background is black when printed via Firefox


richardc

Recommended Posts

I have jfreecharts which are displayed in HTML and can be printed via the browser's print button.

 

The problem is in Mozilla Firefox, when a chart is printed, the key area below the chart prints with a black background. Please see the attached screenshot.

 

I have the following code snippets below (shown in red font) which make the main part of the report background print as white in Firefox. Is there someway to specify that the key area should be white also?

 

JRDesignChart chart = new JRDesignChart(null, chartType);

chart.setBackcolor(Color.WHITE);

...

 

JRHtmlExporter exporter = new JRHtmlExporter();

exporter.setParameter(JRHtmlExporterParameter.JASPER_PRINT_LIST, listOfPrints);

exporter.setParameter(JRHtmlExporterParameter.IMAGES_URI, request.getContextPath()+"/ctx/auth/dashboardimage?image=");

exporter.setParameter(JRHtmlExporterParameter.IS_WHITE_PAGE_BACKGROUND, Boolean.TRUE);

...

 

[file name=chart_print_preview_from_firefox.jpg size=44100]http://www.jasperforge.org/components/com_joomlaboard/uploaded/files/chart_print_preview_from_firefox.jpg[/file]

 

 

I also tried:

chart.getPlot().setBackcolor(Color.WHITE);

chart.getPlot().setBackgroundAlpha(1.0f);

 

But still no luck when printing from Firefox!

The area's outside the plots are still black, so for bar charts, the axis detail can't be seen in the print; for pie charts, the key area under the chart can't be seen in the print.

 

One thing I noticed: in IE browser, the chart image is rendered as a bitmap (this prints ok) - in the Firefox browser, the chart image is rendered as a .png image with transparent regions to the left and underneath chart area - these print as black regions.

 

Any ideas anyone? Teodor?

Post edited by: richardc, at: 2007/05/11 15:04

Link to comment
Share on other sites

  • Replies 3
  • Created
  • Last Reply

Top Posters In This Topic

Hi,

 

I have tested the pie chart in the /demo/samples/charts and does not seem to have the problem with print preview in Firefox.

It might be related to the version of JR or the version of Firefox you are using.

It might be even related to the way to build the report template using the API. In such case, we would need to see the whole code and do tests. A simplified version of the code that would reproduce the problem on our end would help.

 

Thank you,

Teodor

Link to comment
Share on other sites

Hi Teodor,

 

Thank you for looking into this issue.

 

For me also, the Firefox Print Preview looks ok - with no black background regions. The issue of black backgrounds actually occurs after pressing 'Print' in Firefox: the page prints with black background regions around the charts and similarly my printer's 'print preview' window displays the black backround regions.

 

Would it be possible for you to test printing out the sample pie chart you referred to using the Firefox print button?

 

Thanks again.

Link to comment
Share on other sites

Hi Teodor,

 

Here's more detail and findings.

 

From some searching on google:

 

Most browsers can't print partially transparent PNG images. (ref: http://www.econym.demon.co.uk/googlemaps/custom.htm)

 

Firefox 1,0 won't print any PNG files that have transparency (ref: http://groups.google.com/group/Google-Maps-API/browse_thread/thread/c06c9736455921b3)

 

Need to find out if either of the following are possible:

 

(1) how to render the entire chart - particularly the surrounding chart axis areas without any transparent regions at all

 

or

 

(2) how to render the chart as a gif instead of png in Firefox

 

 

I am using Firefox version 1.5.0.11

 

Here is more complete code that I am using:

 

Code:
public abstract class Chart
{
protected JasperDesign design = null;
protected JRDesignBand band = null;
protected JRChartDataset dataset = null;
protected JRDesignChart chart = null;
private int pageHeight = 577;
private int pageWidth = 630;
private int chartHeight = pageHeight;

public Chart(byte chartType, boolean small)
throws JRException
{
if(small) {
pageHeight = 385;
pageWidth = 420;
chartHeight = pageHeight;
}

design = new JasperDesign();
design.setName("DataSourceReport");
design.setLanguage("java");
design.setPageWidth(pageWidth);
design.setPageHeight(pageHeight);
design.setColumnWidth(pageWidth);
design.setLeftMargin(0);
design.setRightMargin(0);
design.setBottomMargin(0);
design.setTopMargin(0);

JRDesignField name = new JRDesignField();
name.setName("OID");
name.setValueClass(String.class);
design.addField(name);

band = new JRDesignBand();
band.setHeight(pageHeight);
design.setTitle(band);

chart = new JRDesignChart(null, chartType);
chart.setEvaluationTime(JRExpression.EVALUATION_TIME_REPORT);
chart.setPositionType(JRDesignChart.POSITION_TYPE_FIX_RELATIVE_TO_TOP);
chart.setX(0);
chart.setY(0);
chart.setWidth(pageWidth);
chart.setHeight(chartHeight);
chart.setBorder(JRGraphicElement.PEN_THIN);
chart.setBorderColor(Color.BLACK);
chart.setBackcolor(Color.WHITE);
chart.setForecolor(Color.BLACK);

chart.getPlot().setLabelRotation(30);

chart.getPlot().setBackcolor(Color.WHITE);
chart.getPlot().setBackgroundAlpha(1.0f);
chart.setShowLegend(!small);

band.addElement(chart);
}

public void add(Object o)
throws JRException
{
if(JRDesignVariable.class.isInstance(o)) {
design.addVariable((JRDesignVariable)o);
} else if(JRDesignGroup.class.isInstance(o)) {
design.addGroup((JRDesignGroup)o);
} else if(JRDesignField.class.isInstance(o)) {
design.addField((JRDesignField)o);
} else {
throw new JRException("This type of object is not supported with this method.");
}
}

public void compile(ByteArrayOutputStream stream)
throws JRException
{
JRProperties.setProperty(JRProperties.COMPILER_CLASSPATH, "lib/core/jasperreports-1.3.0.jar");
JasperCompileManager.compileReportToStream(design, stream);
}

public String getXML()
throws JRException
{
JRProperties.setProperty(JRProperties.COMPILER_CLASSPATH, "lib/core/jasperreports-1.3.0.jar");

return JasperCompileManager.writeReportToXml(JasperCompileManager.compileReport(design));
}
}

 

and

 

Code:
[code]public static ArrayList displayCharts(Collection dashboards, HttpServletRequest request,
boolean small)
throws Exception, IOException, NoSuchClassDOMetaException, JRException
{
if(dashboards==null) {
throw new Exception("displayCharts() received a null as a collection");
}

if(dashboards.size()==0) {
throw new Exception("displayCharts() received an empty collection");
}

// Create and populate list of JasperPrint objects
ArrayList listOfPrints = new ArrayList(4);
JasperPrint emptyPrint = new JasperPrint();

Iterator dashboardsIterator = dashboards.iterator();

while(dashboardsIterator.hasNext()) {
DashboardChart dashboardChart = (DashboardChart)dashboardsIterator.next();
int index = dashboardChart.getPosition().intValue()-1;

// For single view index should always be 0
if(dashboards.size()==1) {
index = 0;
}

if(dashboardChart.getTemplate()==null) {
listOfPrints.add(index, emptyPrint);
} else {
IData data = null;

if(small) {
data = dashboardChart.getTemplateSmall();
} else {
data = dashboardChart.getTemplate();
}

listOfPrints.add(index,
JasperFillManager.fillReport(data.getBinaryStream(),
new HashMap(),
Utils.createDataSource(dashboardChart)));
}
}

// Process list of print objects into charts
StringBuffer sbuffer = new StringBuffer();

request.getSession().setAttribute(ImageServlet.DEFAULT_JASPER_PRINT_LIST_SESSION_ATTRIBUTE,
listOfPrints);

JRHtmlExporter exporter = new JRHtmlExporter();
exporter.setParameter(JRHtmlExporterParameter.JASPER_PRINT_LIST, listOfPrints);
exporter.setParameter(JRHtmlExporterParameter.IMAGES_URI,
request.getContextPath()+"/ctx/auth/dashboardimage?image=");
exporter.setParameter(JRHtmlExporterParameter.IS_WHITE_PAGE_BACKGROUND, Boolean.TRUE);
exporter.setParameter(JRHtmlExporterParameter.HTML_HEADER, "");
exporter.setParameter(JRHtmlExporterParameter.BETWEEN_PAGES_HTML, DELIMETER);
exporter.setParameter(JRHtmlExporterParameter.HTML_FOOTER, "");
exporter.setParameter(JRExporterParameter.OUTPUT_STRING_BUFFER, sbuffer);
exporter.exportReport();

// Divide output by charts
ArrayList outCharts = new ArrayList(4);
String outString = sbuffer.toString();

StringTokenizer charts = new StringTokenizer(outString, DELIMETER);
dashboardsIterator = dashboards.iterator();

while(dashboardsIterator.hasNext()) {
DashboardChart dashboardChart = (DashboardChart)dashboardsIterator.next();
int index = dashboardChart.getPosition().intValue()-1;

// For single view index should always be 0
if(dashboards.size()==1) {
index = 0;
}

if(dashboardChart.getTemplate()==null) {
outCharts.add(index, "Please setup this chart");
} else if(((JasperPrint)listOfPrints.get(index)).getPages().size()==0) {
outCharts.add(index, "There is no data in the system to run this report on.");
} else {
if(!charts.hasMoreTokens()) {
throw new Exception("Charts ran out faster then needed.");
}

outCharts.add(index,
charts.nextToken());
}
}

return outCharts;
}

Post edited by: richardc, at: 2007/05/23 02:07

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×
×
  • Create New...