GeoChart get selection Functionality

682 views
Skip to first unread message

Jason Spencer

unread,
Jan 23, 2017, 2:40:26 AM1/23/17
to Google Visualization API
Hey Guys,

I was hoping maybe one of you guys could help - i am trying to use the get selection so that when one clicks on a specific country they get sent too a new page. but as soon as i put the get selection method in my code  the chart no longer drew... (just a plain white screen)

Below is the java script - any help you could give would be GREATLY appreciated!!
========================================================================================
//geochates code
google.charts.load('upcoming', {'packages':['geochart']});
      google.charts.setOnLoadCallback(drawRegionsMap);

      function drawRegionsMap() {
       
        var data = google.visualization.arrayToDataTable([
          ['Country', 'Languages', 'Frequency ', ' % of Total'],
          ['England','English' , 757, 16.3],
          ['Malaysia', 'Malay', 56, 1.2],
         ]);
        var options = {
              colorAxis: {colors:['#c6d8b8','#b8cfa7','#b1ca9e','#a1bf8b','#91b477','#82aa64','#729f51', '#63953E','#598637','#577740','#45682b','#3b5925','#314a1f'],
                          values: [5,6,8,9,10,17,21,43,46,56,757,839,2727]},
              backgroundColor: '#639bb7',
              datalessRegionColor: '#DFDFD0',
              defaultColor: '#f5f5f5',
            };
       
        var chart = new google.visualization.GeoChart(document.getElementById('regions_div'));
        chart.draw(data, options);
//start of get selection functionality
        google.visualization.events.addListener(chart, 'select', function () {
        var selection = chart.getSelection();
        var value = data.getValue(selection[0].row, 0);

       if (value == 'England'|| value =='English') {
            window.location.href = "england.html";
        }
        }
    }

//=========================================================
 Thank you

Selva Kumar A

unread,
Jan 23, 2017, 11:10:25 PM1/23/17
to Google Visualization API
//geochates code
google.charts.load('upcoming', {'packages':['geochart']});
      google.charts.setOnLoadCallback(drawRegionsMap);

      function drawRegionsMap() { 
        
        var data = google.visualization.arrayToDataTable([
          ['Country', 'Languages', 'Frequency ', ' % of Total'],
          ['England','English' , 757, 16.3],
          ['Malaysia', 'Malay', 56, 1.2],
         ]);
        var options = {
              colorAxis: {colors:['#c6d8b8','#b8cfa7','#b1ca9e','#a1bf8b','#91b477','#82aa64','#729f51', '#63953E','#598637','#577740','#45682b','#3b5925','#314a1f'],
                          values: [5,6,8,9,10,17,21,43,46,56,757,839,2727]},
              backgroundColor: '#639bb7',
              datalessRegionColor: '#DFDFD0',
              defaultColor: '#f5f5f5',
            };
        
        var chart = new google.visualization.GeoChart(document.getElementById('regions_div'));
        chart.draw(data, options);
//start of get selection functionality 
        google.visualization.events.addListener(chart, 'select', function () {
      
       /* Change by Se...@immaculate-ds.com

var selectedItem = chart.getChart().getSelection()[0];
         if (selectedItem) {
var value = chart.getDataTable().getValue(selectedItem.row, 1);
 if (value == 'England'|| value =='English') {
            window.location.href = "england.html";
        }
                        }

*/
//Change end by 


        var selection = chart.getSelection();
        var value = data.getValue(selection[0].row, 0);

       if (value == 'England'|| value =='English') {
            window.location.href = "england.html";
        }
        }
    }
******************************************************************************************************************

Jason Spencer

unread,
Jan 24, 2017, 2:07:57 AM1/24/17
to google-visua...@googlegroups.com
Hi Selva ,
Thank you for trying to help me - unfortunatley my code still isnt working.
Thanks again!

--
You received this message because you are subscribed to a topic in the Google Groups "Google Visualization API" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/google-visualization-api/IFvwMFkg6UQ/unsubscribe.
To unsubscribe from this group and all its topics, send an email to google-visualization-api+unsub...@googlegroups.com.
To post to this group, send email to google-visualization-api@googlegroups.com.
Visit this group at https://groups.google.com/group/google-visualization-api.
To view this discussion on the web visit https://groups.google.com/d/msgid/google-visualization-api/ec52a311-7e36-4401-ba47-2b018a5bfc15%40googlegroups.com.

For more options, visit https://groups.google.com/d/optout.

Selva Kumar A

unread,
Jan 24, 2017, 2:50:25 AM1/24/17
to google-visua...@googlegroups.com

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">

<head>
    <meta http-equiv="content-type" content="text/html; charset=utf-8" />

         


  <script type="text/javascript" src="https://www.gstatic.com/charts/loader.js"></script>
    <script>
    

       google.charts.load('upcoming', {'packages':['geochart']});
      google.charts.setOnLoadCallback(drawRegionsMap);

      function drawRegionsMap() { 
        
        var data = google.visualization.arrayToDataTable([
          ['Country', 'Languages', 'Frequency ', ' % of Total'],
          ['England','English' , 757, 16.3],
          ['Malaysia', 'Malay', 56, 1.2],
         ]);
        var options = {
              colorAxis: {colors:['#c6d8b8','#b8cfa7','#b1ca9e','#a1bf8b','#91b477','#82aa64','#729f51', '#63953E','#598637','#577740','#45682b','#3b5925','#314a1f'],
                          values: [5,6,8,9,10,17,21,43,46,56,757,839,2727]},
              backgroundColor: '#639bb7',
              datalessRegionColor: '#DFDFD0',
              defaultColor: '#f5f5f5',
            };
        
        var chart = new google.visualization.GeoChart(document.getElementById('regions_div'));
        chart.draw(data, options);
//start of get selection functionality 
       
 google.visualization.events.addListener(chart, 'select', function () {
     var selection = chart.getSelection()[0];
     var message = '';


if(selection)
{
//alert('You selected ' + data.getValue(selection.row, 0));
var value=data.getValue(selection.row, 0);
 if (value == 'England'|| value =='English') {
            window.location.href = "england.html";
        }
}


        });
    }


</script>

<body>
    <div id="regions_div" style="width: 900px; height: 500px;"></div>
  </body>

To unsubscribe from this group and all its topics, send an email to google-visualization-api+unsubscr...@googlegroups.com.

--
You received this message because you are subscribed to a topic in the Google Groups "Google Visualization API" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/google-visualization-api/IFvwMFkg6UQ/unsubscribe.
To unsubscribe from this group and all its topics, send an email to google-visualization-api+unsub...@googlegroups.com.
To post to this group, send email to google-visualization-api@googlegroups.com.
Visit this group at https://groups.google.com/group/google-visualization-api.

For more options, visit https://groups.google.com/d/optout.



--
regards
Selva

Jason Spencer

unread,
Jan 24, 2017, 3:03:46 AM1/24/17
to google-visua...@googlegroups.com
My apologies - i was being stupid you code was perfect - i just made a syntax error.
thank you for your help :)

To unsubscribe from this group and all its topics, send an email to google-visualization-api+unsubscr...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages