修改
终于想通了。您需要将其添加到项目中。记录可能是件好事:
页面上没有显示图表,即使可以通过Firebug获得javascript等代码。
我正在使用Mojarra和Primefaces 3
<h:form> <p:growl id="growl" showDetail="true" /> <p:pieChart value="#{distributionChart.pieModel}" legendPosition="w" title="Interactive Pie Chart" style="width:400px;height:300px"> <p:ajax event="itemSelect" listener="#{distributionChart.itemSelect}" update="growl" /> </p:pieChart> </h:form>
支持bean
@Named
@RequestScoped
public class DistributionChart implements Serializable {
@Inject
private QuestionServiceBean questionService;
private CartesianChartModel categoryModel;
private PieChartModel pieModel;
private List<QuestionCategoryDistribution> distribution;
@PostConstruct
public void init() {
distribution = questionService.getQuestionCategoryDistribution();
createPieModel();
}
public void itemSelect(ItemSelectEvent event) {
FacesMessage msg = new FacesMessage(FacesMessage.SEVERITY_INFO, "Item selected",
"Item Index: " + event.getItemIndex() + ", Series Index:" + event.getSeriesIndex());
FacesContext.getCurrentInstance().addMessage(null, msg);
}
public PieChartModel getPieModel() {
return pieModel;
}
private void createPieModel() {
pieModel = new PieChartModel();
for (QuestionCategoryDistribution obj : distribution) {
pieModel.set(obj.getCategoryDescription(), obj.getNumberOfQuestions());
}
}
}