I apologize in advance if this has been answered somewhere else before, but I have been unable to find an answer on my own. I am having trouble using the printer object to print chart components. I worked up a simple line chart demo based off the showcase code, and added a CommandButton and printer behavior to print the LineChart component. However, the print out only contains the legend and value ticks along the chart axes. None of the actual data series lines, points, nor the grid backing of the chart show up in the printout.
Is this a known bug, or am I just missing something? If it is a known bug, will it be fixed? Is there a work around for printing chart data?
Thank you, and my code follows:
Here is my chart.xhtml
Code: Select all
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:p="http://primefaces.org/ui">
<h:head>
<title>Primefaces Chart test</title>
</h:head>
<h:body>
<f:loadBundle basename="com.dashboard.MessageBundle" var="bundle"/>
<f:view contentType="text/html">
<h:commandButton value="Print" type="button" icon="ui-icon-print">
<p:printer target="linear" />
</h:commandButton>
<p:lineChart id="linear" value="#{chartBean.model}" legendPosition="e" title="Linear Chart" minY="0" maxY="10" style="height:300px"/>
</f:view>
</h:body>
</html>
Code: Select all
<?xml version="1.0" encoding="UTF-8"?>
<faces-config version="2.0" xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xi="http://www.w3.org/2001/XInclude"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-facesconfig_2_0.xsd">
<managed-bean>
<managed-bean-name>chartBean</managed-bean-name>
<managed-bean-class>com.dashboard.controller.LineChartControllerBean</managed-bean-class>
<managed-bean-scope>session</managed-bean-scope>
</managed-bean>
<navigation-rule>
<from-view-id>/chart.xhtml</from-view-id>
</navigation-rule>
</faces-config>
Code: Select all
package com.dashboard.controller;
import java.util.ArrayList;
import java.util.List;
import org.primefaces.model.chart.CartesianChartModel;
import org.primefaces.model.chart.LineChartSeries;
public class LineChartControllerBean extends ChartControllerBean {
protected List<LineChartSeries> seriesList;
public LineChartControllerBean() {
model = new CartesianChartModel();
initializeSeriesList();
initializeModel();
}
public List<LineChartSeries> getSeriesList() {
if(seriesList == null) {
seriesList = new ArrayList<LineChartSeries>();
}
return seriesList;
}
public void setSeriesList(List<LineChartSeries> seriesList) {
this.seriesList = seriesList;
}
public void addSeries(LineChartSeries series) {
getSeriesList().add(series);
}
public void removeSeries(int index) {
getSeriesList().remove(index);
}
private void initializeSeriesList() {
LineChartSeries series1 = new LineChartSeries();
series1.setLabel("Series 1");
series1.set(1, 2);
series1.set(2, 1);
series1.set(3, 3);
series1.set(4, 6);
series1.set(5, 8);
addSeries(series1);
LineChartSeries series2 = new LineChartSeries();
series2.setLabel("Series 2");
series2.setMarkerStyle("diamond");
series2.set(1, 6);
series2.set(2, 3);
series2.set(3, 2);
series2.set(4, 7);
series2.set(5, 9);
addSeries(series2);
}
private void initializeModel() {
for(LineChartSeries series : getSeriesList()) {
((CartesianChartModel)model).addSeries(series);
}
}
}
Code: Select all
package com.dashboard.controller;
import org.primefaces.model.chart.ChartModel;
public abstract class ChartControllerBean {
protected ChartModel model;
public ChartControllerBean() {
}
public ChartModel getModel()
{
return model;
}
public void setModel(ChartModel model)
{
this.model = model;
}
public String toString() {
StringBuilder str = new StringBuilder();
str.append(this.getClass());
return str.toString();
}
}