Customizing tooltip on a line chart category

2,116 views
Skip to first unread message

Oliver Chang

unread,
Mar 27, 2013, 6:15:41 PM3/27/13
to google-visua...@googlegroups.com
Hi,

I have a question about how to customize a line chart with two series when the focusTarget: "category" option is set. Is there a way to customize the display of the tooltip like there is when focusTarget is set to datum? Using a column set to the tooltip role doesn't seem to work since that just returns the default tooltip with raw HTML, instead of the customized, rendered HTML tooltip.

For example, taking an example from the Data Roles docs,

 google.load('visualization''1.1'{'packages':['corechart']});

 google.setOnLoadCallback(drawChart_C6);

  function drawChart_C6({
    var data new google.visualization.DataTable();
    data.addColumn({type'string'role'domain'}'2009 Quarter');
    data.addColumn('number''2009 Sales');
    data.addColumn('number''2009 Expenses');
    data.addColumn({type'string'role'domain'}'2008 Quarter');
    data.addColumn('number''2008 Sales');
    data.addColumn('number''2008 Expenses');
    
    // tooltip column
    data.addColumn(type"string"role"tooltip"phtmltrue }});
    
    data.addRows([
      ['Q1 \'09'1000400'Q1 \'08'800300"<h1>tooltip</h1>"],
      ['Q2 \'09'1170460'Q2 \'08'750400"<h1>tooltip</h1>"],
      ['Q3 \'09'6601120'Q3 \'08'700540"<h1>tooltip</h1>"],
      ['Q4 \'09'1030540'Q4 \'08'820620"<h1>tooltip</h1>"]
    ]);

    var chart new google.visualization.LineChart(document.getElementById('visualization'));
    chart.draw(data{width400height240legend:'right'focusTarget'category'tooltip{isHtmltrue}});
  }


Is what I'm asking possible using a category focusTarget? Thanks in advance.

asgallant

unread,
Mar 27, 2013, 6:55:46 PM3/27/13
to google-visua...@googlegroups.com
You can use the HTML tooltips, but you have to assign them to the domain column, not the data columns.  See example here: http://jsfiddle.net/asgallant/q85yL/.  Note that in the example code, there is very little reason to include a second domain column (I left it in for consistency with the code you posted, but it can be removed without affecting anything in the chart).

Oliver Chang

unread,
Mar 27, 2013, 8:25:02 PM3/27/13
to google-visua...@googlegroups.com
Thanks for the tips and the solution. It worked perfectly!

Ravindra Gharge

unread,
Feb 20, 2014, 4:27:41 AM2/20/14
to google-visua...@googlegroups.com
In this example is it possible to add control which will filter the  2009 Sales , 2009 Expenses , 2008 Sales , 2008 Expense

Thanks

asgallant

unread,
Feb 20, 2014, 11:04:08 AM2/20/14
to google-visua...@googlegroups.com
You can filter each series individually, but there is no built-in method of filtering all series with a single control if that is what you are asking.
Reply all
Reply to author
Forward
0 new messages