Thursday, January 24, 2013

Bar Graph -2

Hi

In my last post i have given example for creating model of bar graph by passing value in tabular data.In this post i will create the model of graph by using LocalXMLDataSource and GraphDataModel.Then pass the value in the value property of bar graph.

Explanation is following

1-First defined variable  in backing bean

private GraphDataModel graphDataModel;

2-Created setter and getter of above variable

    public void setGraphDataModel(GraphDataModel graphDataModel) {
        this.graphDataModel = graphDataModel;
    }

    public GraphDataModel getGraphDataModel() {
               return graphDataModel;
    }

3-Whole code of backing bean is following.In getter method i have created object of LocalXMLDataSource then set into GraphDataMode object .

package com.example.oracle.backingbean;

import oracle.adf.view.faces.bi.model.GraphDataModel;

import oracle.dss.dataView.LocalXMLDataSource;

public class BarGraphBackingBean {
    public BarGraphBackingBean() {
        super();
    }

    private GraphDataModel graphDataModel;

    public void setGraphDataModel(GraphDataModel graphDataModel) {
        this.graphDataModel = graphDataModel;
    }

    public GraphDataModel getGraphDataModel() {
        if (graphDataModel == null) {
            graphDataModel = new GraphDataModel();
            LocalXMLDataSource ds = new LocalXMLDataSource(columnsValue(), seriesValue(), dataPoint());
            graphDataModel.setDataSource(ds);
        }
        return graphDataModel;
    }

    public String[] seriesValue() {
        String[] seriesLabels = { "Series_1", "Series_2", "Series_3"};
        return seriesLabels;
    }

    public String[] columnsValue() {
        String[] columnLabels = { "Column_1","Column_2" };
        return columnLabels;
    }

    public Object[][] dataPoint() {
        Object[][] dataPoint = new Object[2][3];
        dataPoint[0][0] = new Double(10);
        dataPoint[0][1] = new Double(20);
        dataPoint[0][2] = new Double(30);
        dataPoint[1][0] = new Double(40);
        dataPoint[1][1] = new Double(50);
        dataPoint[1][2] = new Double(60);
        return dataPoint;
    }
}

*Two column
*Three Series
*And each column has three data point value.

Step 4:Page code is following

<?xml version='1.0' encoding='UTF-8'?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<f:view xmlns:f="http://java.sun.com/jsf/core" xmlns:af="http://xmlns.oracle.com/adf/faces/rich"
        xmlns:dvt="http://xmlns.oracle.com/dss/adf/faces">
    <af:document title="barGraphPage.jsf" id="d1">
        <af:form id="f1">
            <dvt:barGraph id="graph1" subType="BAR_VERT_CLUST" value="#{barGraphBackingBean.graphDataModel}">
                <dvt:background>
                    <dvt:specialEffects/>
                </dvt:background>
                <dvt:graphPlotArea/>
                <dvt:seriesSet>
                    <dvt:series/>
                </dvt:seriesSet>
                <dvt:o1Axis/>
                <dvt:y1Axis/>
                <dvt:legendArea automaticPlacement="AP_NEVER"/>
            </dvt:barGraph>
        </af:form>
    </af:document>
</f:view>


Here i have created two column and each column has contains 3 series.
Running page screen is following



Code is present at following location

https://docs.google.com/file/d/0B8cP4jZuxLlXRXljdHNXRDlJVTg/edit?usp=sharing

Thanks,
Prateek

No comments:

Post a Comment

Post a Comment