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() + ", Item Index: " + event.getItemIndex()); }
How it works…
ItemSelectEvent
is a wrapper class that contains seriesIndex
, the series that the item resides inside, and itemIndex
, the position of the item within...