tooltip not working with legend in cloumn chart

67 views
Skip to first unread message

Ravindra Gharge

unread,
Feb 20, 2014, 5:49:07 AM2/20/14
to google-visua...@googlegroups.com
I want my legend in my column chart and want to customize the tooltip on hovering the chart column

following is my code :
if i remove my legend part it will work but i want to keep my legend in my chart
\google.setOnLoadCallback(drawChart);

function drawChart() {
  var dataTable = google.visualization.arrayToDataTable([
['state' , 'count', 'null'],
['', 16,'Total Count'],
['Assam', 4,'Total Count'],
['Chhattisgarh', 1,'Total Count'],
['Maharashtra', 245,'Total Count'],
['Meghalaya', 17,'Total Count'],
['Odisha', 13,'Total Count'],
['Undefined', 2,'Total Count'],
['West Bengal', 11,'Total Count'] ]);
 
  // A column for custom tooltip content
  //dataTable.addColumn({type: 'string', role: 'tooltip'});

  var pausecontent = ["West Bengal", "Undefined", "Odisha", "Meghalaya", "Maharashtra", "Chhattisgarh", "Assam", ""];
    /****************************************************************/
    // set the columns to use in the chart's view (columns object is used in the view)
    // calculated columns put data belonging to each country in the proper column
    var columns = [0];
    for (var i = 0; i < pausecontent.length; i++) {
        columns.push({
            type: 'number',
            label: pausecontent[i],
            calc: (function (x) {
                return function (dt, row) {
                   //return (row == pausecontent[x]) ? dt.getValue(row, 1) : null;
                    return (dt.getValue(row, 0) == pausecontent[x]) ? dt.getValue(row, 1) : null;
                }
            })(i)
        });
    }
  
  dataTable.setColumnProperty(2, 'role', 'tooltip');
  //var options = { legend: 'none', };
  //var chart = new google.visualization.ColumnChart(document.getElementById('visualization'));
           var chart = new google.visualization.ChartWrapper({
        chartType: 'ColumnChart',
        containerId: 'visualization',
        dataTable: dataTable,
        options: {
          // setting the "isStacked" option to true fixes the spacing problem
          'title': 'State Wise Coverage Performance',
          'isStacked': true,
          'height': 300,
          'width': 800,
          bar: {groupWidth: '90%'},
      
        },
        view: {
            columns: columns
        }
    });
          
          
  chart.draw();
}

Please help ,
Thanks in advance

asgallant

unread,
Feb 20, 2014, 11:53:53 AM2/20/14
to google-visua...@googlegroups.com
If you want to keep your custom tooltips, you have to add tooltip columns to your columns array:

for (var i = 0; i < pausecontent.length; i++) {
    columns.push({
        type: 'number',
        label: pausecontent[i],
        calc: (function (x) {
            return function (dt, row) {
                return (dt.getValue(row, 0) == pausecontent[x]) ? dt.getValue(row, 1) : null;
            }
        })(i)
    });

    columns.push({
        type: 'string',
        role: 'tooltip',
        calc: (function (x) {
            return function (dt, row) {
                return (dt.getValue(row, 0) == pausecontent[x]) ? dt.getValue(row, 2) : null;
            }
        })(i)
    });

Ravindra Gharge

unread,
Feb 20, 2014, 10:09:33 PM2/20/14
to google-visua...@googlegroups.com
Thanks It's working....


--
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/0Hrs1cuErhY/unsubscribe.
To unsubscribe from this group and all its topics, send an email to google-visualizati...@googlegroups.com.
To post to this group, send email to google-visua...@googlegroups.com.
Visit this group at http://groups.google.com/group/google-visualization-api.
For more options, visit https://groups.google.com/groups/opt_out.

Ravindra Gharge

unread,
Feb 21, 2014, 7:33:37 AM2/21/14
to google-visua...@googlegroups.com

For above example,

if object have 0 count for some of the states then i want to skip this states from the chart object.
because it waste the unnecessary space in the chart and legend

and

Is their any way of setting the custom tooltip for given chart without modifying the given object (in my example - without specifying null column as tooltip) because doing this doing this object size increases...

asgallant

unread,
Feb 21, 2014, 10:20:21 AM2/21/14
to google-visua...@googlegroups.com
You can find out what states have data by calling dataTable.getDistinctValues(0).

If you don't have a column that specifies your tooltips, how would you like to create the tooltip contents?  The DataView can create the text contents for you, if you want.  As an example, if you wanted all of your tooltips to read "Total Count" (like in your example), you could do this:

columns.push({
    type: 'string',
    role: 'tooltip',
    calc: (function (x) {
        return function (dt, row) {
            return (dt.getValue(row, 0) == pausecontent[x]) ? 'Total Count' : null;
        }
    })(i)
});
Reply all
Reply to author
Forward
0 new messages