1. Create a pie graph
2. Make Data Selection property as Single
3. Add ClickListener in Bean
[code]<dvt:pieGraph id="graph1" value="#{bindings.ViewObject1.graphModel}" subType="PIE"
threeDEffect="true" animationOnDisplay="auto" hideAndShowBehavior="withRescale"
seriesRolloverBehavior="RB_HIGHLIGHT" dynamicResize="DYNAMIC_SIZE"
shortDesc="Delivery By Period" clickListener="#{bean.pieClickListener}">
[/code]
4. Add this code in bean
String deliveryDate = null;
String customerCode = null;
String customerName = null;
MyUtil.invokeEL("#{bindings.ViewObject1.graphModel.processClick}", new Class[] { ClickEvent.class },
new Object[] { clickEvent });
// get selected row (Use pie chart iterator name)
Row selectedRow = (Row) myUtil.evaluateEL("#{bindings.ViewObject1Iterator.currentRow}");
//get attribute from selected row
customerCode = (String)selectedRow.getAttribute("CustomerCode");
deliveryDate = selectedRow.getAttribute("DeliveryDate").toString();
customerName = (String)selectedRow.getAttribute("CustomerName");
System.out.println("Delivery Date : "+deliveryDate);
System.out.println("Customer Code : "+customerCode);
System.out.println("Customer Name : "+customerName);
}
5. Here are the helper methods
public static Object invokeEL(String el, Class[] paramTypes, Object[] params) {
FacesContext facesContext = FacesContext.getCurrentInstance();
ELContext elContext = facesContext.getELContext();
ExpressionFactory expressionFactory = facesContext.getApplication().getExpressionFactory();
MethodExpression exp = expressionFactory.createMethodExpression(
elContext, el, Object.class, paramTypes);
return exp.invoke(elContext, params);
}
public static Object evaluateEL(String el) {
FacesContext facesContext = FacesContext.getCurrentInstance();
ELContext elContext = facesContext.getELContext();
ExpressionFactory expressionFactory = facesContext.getApplication().getExpressionFactory();
ValueExpression exp = expressionFactory.createValueExpression(elContext, el, Object.class);
return exp.getValue(elContext);
}