Getting a dashboard to draw from a pull-down menu's onChange function

100 views
Skip to first unread message

rtrigg

unread,
Jul 2, 2012, 1:54:29 AM7/2/12
to google-visua...@googlegroups.com
Hi Google Vis gurus,

This is probably dead easy, and I'm missing the obvious.  I've got a google visualization dashboard with controllers and charts.  I've built a menu outside the dashboard that lets the user choose between displaying total $ and counts.  The charts in the dashboard dynamically re-configure themselves depending on that menu selection. 

My problem is that I want the draw method of the dashboard to be invoked when the user makes a selection in the menu, that is, from the menu's onChange function.  I'm using the setonloadcallback method to invoke an Init function that contains the definition of the dashboard, data table, etc.  How the heck do I invoke the draw method for that dashboard from outside the Init function?  I tried declaring the dashboard var outside the Init function to no avail.  Does the solution involve jquery?

Here's the skeleton of my code:

google.load('visualization', ...);
google.setOnLoadCallback(Init);

function Init () {

 var data = new google.visualization.DataTable();
 data.addColumn (...);
 data.addRows (...);

 dashboard = new google.visualization.Dashboard(
        document.getElementById('dashboard_div'));

 <ControlWrapper/chart definitions, bindings>
 dashboard.draw(data);

};

Thanks in advance!

   - Randy

asgallant

unread,
Jul 2, 2012, 11:22:09 AM7/2/12
to google-visua...@googlegroups.com
It is easy, you just need to assign the "onChange" event handler inside the init function:

google.load('visualization'...);
google.setOnLoadCallback(Init);

function Init({

    var data new google.visualization.DataTable();
    data.addColumn(...);
    data.addRows(...);

    dashboard new google.visualization.Dashboard(
    document.getElementById('dashboard_div'));

    // <ControlWrapper / chart definitions, bindings>
    
    dashboard.draw(data);

    document.getElementById('myDropDown').onchange function ({
        // get the dropdown value and change settings as necessary
        
        dashboard.draw(data);
    };
}; 

rtrigg

unread,
Jul 3, 2012, 8:31:33 PM7/3/12
to google-visua...@googlegroups.com
Thanks - that's simple and elegant and works like a champ!

   - Randy
Reply all
Reply to author
Forward
0 new messages