How to add DVT Graph Programmatically

This tutorial is to show how to inject a DVT graph programmatically in Oracle ADF

Step 1: Define a List Data Model:

Java Code for Data

        List<Object[]> listObject = null;
        if (listObject == null) {
            listObject = new ArrayList<Object[]>();
            Object[] obj1 = { "Example_Bar_1", "Series_1", 10 };
            Object[] obj2 = { "Example_Bar_1", "Series_2", 15 };
            Object[] obj3 = { "Example_Bar_1", "Series_3", 75 };
            listObject.add(obj1);
            listObject.add(obj2);
            listObject.add(obj3);
        }

JSFF Code where the code will be injected:

<?xml version='1.0' encoding='windows-1252'?>
<jsp:root xmlns:jsp="http://java.sun.com/JSP/Page" version="2.1"
 xmlns:f="http://java.sun.com/jsf/core"
 xmlns:h="http://java.sun.com/jsf/html"
 xmlns:af="http://xmlns.oracle.com/adf/faces/rich"
 xmlns:dvt="http://xmlns.oracle.com/dss/adf/faces">
 <jsp:directive.page contentType="text/html;charset=windows-1252"/>
 <f:view>
 <af:document title="demo" id="d1">
 <af:form id="f1">
 <af:panelGroupLayout id="pgl1" styleClass="container" binding="#{backingBeanScope.graphBean.container}"/>
 </af:form>
 </af:document>
 </f:view>
</jsp:root>

Java Code to inject Graph @ Runtime:

[Note]:container is the binding to the af:panelGroupLayout under which you wish to inject the graph
        List<Object[]> listObject = null;
        if (listObject == null) {
            listObject = new ArrayList<Object[]>();
            Object[] obj1 = { "Example_Bar_1", "Series_1", 10 };
            Object[] obj2 = { "Example_Bar_1", "Series_2", 15 };
            Object[] obj3 = { "Example_Bar_1", "Series_3", 75 };
            listObject.add(obj1);
            listObject.add(obj2);
            listObject.add(obj3);
        }
        UIGraph graph = new UIGraph();
        graph.setGraphType(UIGraph.PIE);
        graph.setTabularData(listObject);
        container.getChildren().add(graph);

Result:

2015-08-14_1742