I attempt to use <p:chart>
with LineChartModel
, but when I load the page, nothing is displayed and there is a JS error.
This is my model
@ManagedBean
@SessionScoped
public class InterfaceBean {
private LineChartModel model = new LineChartModel();
@PostConstruct
public void init()
{
this.drawInterfaceChart();
}
public void drawInterfaceChart(){
model = initLineChartModel();
model.setTitle("toto");
model.setAnimate(true);
model.setLegendPosition("se");
Axis yAxis = model.getAxis(AxisType.Y);
yAxis.setMin(0);
yAxis.setMax(100);
}
private LineChartModel initLineChartModel(){
LineChartModel model = new LineChartModel();
LineChartSeries series = new LineChartSeries();
int limit = (listExecution.size() > 10) ? 10 : listExecution.size();
for (int i=0; i<limit; i++)
{
series.set("execution "+i, listExecution.get(i).getSuccessRate());
}
model.addSeries(series);
return model;
}
}
This is my view
<h:panelGrid columns="2" columnClasses="left,right" style="width:100%">
<p:chart type="line" rendered="true" model="#{interfaceBean.model}" style="width:400px;" />
</h:panelGrid>
This is the JS error
Uncaught TypeError: Cannot read property 'LinearAxisRenderer' of undefined
After reading so many topics about this kind of problem, I added this on the web page
<h:outputStylesheet name="charts/charts.css" library="primefaces" />
<h:outputScript name="charts/charts.js" library="primefaces" />
But I still have the same JavaScript error and the lineChart
is always not displayed.
How is this caused and how can I solve it?