selecthandler function in google charts

69 views
Skip to first unread message

rakesh h

unread,
Jul 25, 2017, 3:04:59 AM7/25/17
to Google Visualization API
I have loaded two different data pie chart in a single page.I have used two different selecthandler function for two pie charts to get the slice name.
But when i select first pie chart slice i am getting second chart slice name.Whats the problem?

first chart selecthandler function

google.visualization.events.addListener(mychart1,'select',selectHandler1);
      function selectHandler1() {
        var selection1 = mychart1.getSelection();
        var message = '';
        for (var i = 0; i < selection1.length; i++) {
          var item = selection1[i];
          if (item.row != null && item.column != null) {
            var str1 = data.getFormattedValue(item.row, item.column);
            message += '{row:' + item.row + ',column:' + item.column + '} = ' + str1 + '\n';
          } 
          else if (item.row != null) {
            var str1 = data.getFormattedValue(item.row, 0);
            message += '{row:' + item.row + ', column:none}; value (col 0) = ' + str1 + '\n';
          }
          else if (item.column != null) {
            var str1 = data.getFormattedValue(0, item.column);
            message += '{row:none, column:' + item.column + '}; value (row 0) = ' + str1 + '\n';
          }
        }
        if (message == '') {
          message = 'nothing';
        }
              alert(str1);
      }

second chart selecthandler function

google.visualization.events.addListener(mychart2,'select',selectHandler2);
      function selectHandler2() {
        var selection2 = mychart2.getSelection();
        var message = '';
        for (var i = 0; i < selection2.length; i++) {
          var item = selection2[i];
          if (item.row != null && item.column != null) {
            var str2 = data.getFormattedValue(item.row, item.column);
            message += '{row:' + item.row + ',column:' + item.column + '} = ' + str2 + '\n';
          } 
          else if (item.row != null) {
            var str2 = data.getFormattedValue(item.row, 0);
            message += '{row:' + item.row + ', column:none}; value (col 0) = ' + str2 + '\n';
          }
          else if (item.column != null) {
            var str2 = data.getFormattedValue(0, item.column);
            message += '{row:none, column:' + item.column + '}; value (row 0) = ' + str2 + '\n';
          }
        }
        if (message == '') {
          message = 'nothing';
        }
              alert(str2);
      }

Daniel LaLiberte

unread,
Jul 25, 2017, 6:56:50 AM7/25/17
to Google Visualization API
What we can't see from your code is exactly what you need to look at also, which is how the mychart1 and mychart2 might be sharing the same data, or possibly even the same container element.  If you can post a more complete example showing this problem, that will let us provide more help.

--
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 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/6fba1dd7-00b8-4e85-bbcc-ff60a173e170%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.



--
Reply all
Reply to author
Forward
0 new messages