Interacting with charts through AJAX

PrimeFaces' chart components support the itemSelect AJAX behavior event, which is fired when an item on the plotted data is clicked upon.

How to do it...

A simple definition for a bar chart, with a listener attached and two series of data to be displayed, is given as follows:

<p:barChart id="withAjax" value="#{barChartController.model}" style="height:250px">
  <p:ajax event="itemSelect" listener="#{barChartController.itemSelect}" update="growl" />
</p:barChart>

The listener is defined with the p:ajax component and will be called with the org.primefaces.event.ItemSelectEvent attribute.

public void itemSelect(ItemSelectEvent event) { MessageUtil.addInfoMessageWithoutKey("Item selected", "Series Index:" + event.getSeriesIndex() ...

Get PrimeFaces Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.