Hello ChartMan,

We are actually trying to create a chart with multiple grouping of
data for a XAxis field. It is the same concept as we apply in grouping
the data using SQL.

Here is some explaination of the code example that I had posted:

Structure of ChartTableDataObject
public class ChartDataTableObject implements IsSerializable {
private ArrayList<ChartDataTableValuesObject> dataTableValuesObjList =
new ArrayList<ChartDataTableValuesObject>();
private String xAxisTitle;
private String yAxisTitle;
private String yAxisField;

public ArrayList<String> getXAxisFields(){

                ArrayList<String> fields = new ArrayList<String>();
                if(xAxisTitle!=null){
                        String[] xAxisFields = xAxisTitle.split(",");
                        for(int i=0; i<xAxisFields.length; i++){
                                fields.add(xAxisFields[i].trim());
                        }
                }

                return fields;

        }

}

structure of ChartDataTableValuesObject:
/**
 * xAxisField - represents the X Axis Field of the chart
 */
private String xAxisField;

/**
 * valuesPerXAxisField - represents the values of xAxisField.
 * Each <String, Double> is the <label, value> pair.
 */
private TreeMap<String, Double> valuesPerXAxisField;

Here is the code that is being used to set the data.

dataTable.addColumn(ColumnType.STRING,
chartTableObject.getxAxisTitle());// set the title

// following code will add maximum columns depending upon the size of
valuesPerXAxisField for a XAxis field.
// the max size will be the maximum size of Map among all the XAxis
field. Refer to ChartDataTableValuesObject
for (int index = 0; index < maxSize; index++) {
                        dataTable.addColumn(ColumnType.NUMBER, "");
                }

dataTable.addRows(rowSize);// total number of XAxis fields. i.e.
chartTableObject.getDataTableValuesObjList().size();

for (int index = 0; index < rowSize; index++) {// iterate over the
rowSize

// add the X Axis field on rowIndex index
dataTable.setValue(index, 0,
chartTableObject.getDataTableValuesObjList().get(index).getxAxisField());

// get the Map associated with the above xAxisField
Iterator<Map.Entry<String, Double>> mapIterator = chartTableObject
                                        .getDataTableValuesObjList().get(index)
                                        
.getValuesPerXAxisField().entrySet().iterator();

1. iterate over this Map{
colDisplay is the value of the grouped x Axis field
// for example, if XAxis field represents a single grouped field of
Department and Designation database Columns then
// colDisplay will be Account (which is a department)
String colDisplay = pair.getKey();
2. set each of the value in the Map
// here index represents the index of the currently iterated XAxis
field.

dataTable.setCell(index, count, pair.getValue(), colDisplay +"
"+pair.getValue(), null);
// pair.getValue is the count associated with Account & Designation
i.e. 3-Clerk, 5-Accountant etc..
//this represents one stack for grouped XAxis fied
(Account&Desigation)

}

}

Let me know if this clarifys.

Thanks,
Ankit

On Oct 20, 6:27 am, ChartMan <[email protected]> wrote:
> Please send an example page.
>
>
>
> On Mon, Oct 18, 2010 at 7:06 PM, Anky <[email protected]> wrote:
> > Hi,
>
> > I have implemented a chart that displays stacks for each x axis
> > component with multiple values. For example, If I apply two level of
> > grouping on x axis (say A, B fields) then A's data grouped by B's data
> > will be displayed on the A's values which are x Axis coordinates. To
> > illustrate, lets assumea table with columns as Name, Designation,
> > Address, Department EmailD. I want to display the chart data based on
> > grouping of department and designation. So the chart will be plotted
> > with Department - Account having stack values as Account-Manager,
> > Account-Clerk, Account-Accountant. This represents one bar in the
> > column chart. The other bar may have some other department ,say,
> > Library with stack values Library-Checker, Library-issuer etc...
> > Consider that Y Axis has a count field that represents the count of
> > each department-designation
>
> > I am able to plot this chart but the problem comes with display of
> > legends. Legend color is displyed but the legend text is not
> > displayed.
>
> > Here is the datatable method which I am using to set the values
>
> > <code>
> > public DataTable getDataTable() {
> >                dataTable = DataTable.create();
> >                int maxSize = getMaxColumns();// represents how many stacks
> > will be
> > created for each x Axis field.
> > // rowSize - get the number of fields on x Axis.
> >                int rowSize =
> > chartTableObject.getDataTableValuesObjList().size();
>
> >                dataTable.addColumn(ColumnType.STRING,
> > chartTableObject.getxAxisTitle());
> > // add the x Axis fieds
> >                for (int index = 0; index < maxSize; index++) {
> >                        dataTable.addColumn(ColumnType.NUMBER, "");
> >                }
>
> >                dataTable.addRows(rowSize);
> >                for (int index = 0; index < rowSize; index++) {
> > // set the x Axis field
> >                        dataTable.setValue(index, 0, chartTableObject
>
> >  .getDataTableValuesObjList().get(index).getxAxisField());
> > // this MAP holds the key (x axis field) and value(all the values for
> > this field)
> >                        Iterator<Map.Entry<String, Double>> mapIterator =
> > chartTableObject
>
> >  .getDataTableValuesObjList().get(index)
>
> >  .getValuesPerXAxisField().entrySet().iterator();
>
> >                        while (mapIterator.hasNext()) {
> >                                try{
> >                                Map.Entry<String, Double> pair =
> > (Map.Entry<String, Double>)
> > mapIterator
> >                                                .next();
> >                                String colDisplay = pair.getKey();
> >                                int hyphenIndex = colDisplay.indexOf("-");
> >                                colDisplay =
> > colDisplay.substring(hyphenIndex+1,
> > colDisplay.length());
> > // using -> public final native void setCell(int rowIndex, int
> > columnIndex, double value, String
> > // formattedValue,Properties properties)
> > dataTable.setCell(index, count, pair.getValue(), colDisplay+"
> > "+pair.getValue(), null);
> > // it wil display xaxis field something like Account-> 'Manager-12',
> > 'Clerk-15'
>
> >                                }catch (Exception e) {
> >                                        System.out.println("Exception while
> > iterating map to add values
> > to datatable "+e.getMessage());
> >                                }
> >                        }
> >                }
> >                return dataTable;
> >        }
> > </code>
>
> > --
> > You received this message because you are subscribed to the Google Groups
> > "Google Visualization API" group.
> > To post to this group, send email to
> > [email protected].
> > To unsubscribe from this group, send email to
> > [email protected]<google-visualization-­api%[email protected]>
> > .
> > For more options, visit this group at
> >http://groups.google.com/group/google-visualization-api?hl=en.- Hide quoted 
> >text -
>
> - Show quoted text -

-- 
You received this message because you are subscribed to the Google Groups 
"Google Visualization API" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/google-visualization-api?hl=en.

Reply via email to