Hi

I have written a dashboards of sorts, but one that uses a trick I found 
(attributable to asgallant, I think), which allows me to present some 
charts based on a hidden underlying dashboard/datatable.

I'm having an issue with it though, in that the piechart doesn't draw on 
first load of the page, but works fine when a value is selected from the 
CategoryFilter or equally, when selections are removed from that (in effect 
reverting to the initial load state).  Instead, I get an "e is null" error.

Can anyone offer pointers as to what I'm doing wrong?

function drawPCEstate(json) {

    var data = new google.visualization.DataTable(json.d);

    // holds the full data, including the column it will be filtered by
    var pceplacebo = new google.visualization.ChartWrapper({
        'chartType': 'Table',
        'containerId': 'placeboPCE',
        'dataTable':data,
        'view': {
            'rows':[0]
        }
    });
    
    // table to present the summarised pceplacebo data
    var pcetable = new google.visualization.ChartWrapper({
        'chartType': 'Table',
        'containerId': 'config_PCEstate_table',
        'options': {
            'fontName': '"Arial"',
            'fontSize': "10pt",
            'chartArea' : {'width':'100%'}
        }
    });

   // chart to present the summarised pceplacebo data
   var pcechart = new google.visualization.ChartWrapper({
        'chartType': 'PieChart',
        'containerId': 'config_PCEstate_chart',
        'options': {
            'fontName': '"Arial"',
            'fontSize': "10pt",
            'chartArea' : {'width':'100%'}
        }
    });

    // categoryfilter
    var pcefilterdept = new google.visualization.ControlWrapper({
        'controlType': 'CategoryFilter',
        'containerId': 'pce_dept_filter',
        'options': {
            'filterColumnLabel': 'Department',
            'ui': {
                'label': 'Department',
                'labelSeparator': ':',
                'labelStacking': 'vertical',
                'allowTyping': false,
                'allowMultiple': true
            }
        }
    });

    //populate dashboard and bind filter to pceplacebo
    var pcedashboard = new 
google.visualization.Dashboard(document.getElementById('config_PCestate')).bind(pcefilterdept,pceplacebo);
    google.visualization.events.addListener(pcefilterdept, 'statechange', 
pceSummary);
    google.visualization.events.addListener(pcedashboard, 'ready', 
pceSummary);
    pcedashboard.draw(data);
    
    function pceSummary() {
        // build summary table for the current filter
        var tmpdata = pceplacebo.getDataTable();
        var pcesmydata = new 
google.visualization.data.group(tmpdata,[1],[{'column':2,'aggregation':google.visualization.data.sum,
 
'type':'number'}]);
        pcesmydata.sort([{'column':0, 'desc': false}]);

        // ensure consistent colouring on the pieChart - build array of 
colours one for each 'type' in the current selection
        var counter = 0;
        var pieColours = new Array();
        for (var i=0;i < pcesmydata.getNumberOfRows(); i++) {
            var valItem = pcesmydata.getValue(i,0);
            if (valItem == 'Win 7') {
                pieColours[counter] = constGreenA;
            } else if (valItem == 'Win XP') {
                pieColours[counter] = constRedA;
            } else if (valItem == 'Win XP legacy') {
                pieColours[counter] = constAmberA;
            } else {
                pieColours[counter] = constGreyA;
            }
            counter++;
        }

        pcetable.setDataTable(pcesmydata);
        pcetable.draw();  
        pcechart.setDataTable(pcesmydata);
        pcechart.setOption('colors',pieColours);
        pcechart.draw();
    }
}
Thanks.

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


Reply via email to