Delay call to tooltip calc function

23 views
Skip to first unread message

Rivka

unread,
Nov 29, 2015, 7:34:34 AM11/29/15
to Google Visualization API
We have a chart with around 500 points and a custom tooltip function that takes 2 msec to run.
As a consequence, there is a penalty of 1000 msec on chart rendering.

Is there a way to be lazy on tooltip calculation and call the function only upon user interaction?

Or maybe there are other way to be more efficient?

Daniel LaLiberte

unread,
Nov 30, 2015, 9:36:49 AM11/30/15
to Google Visualization API
Hi Rivka,

If you use html tooltips, the contents can be computed dynamically if you handle the 'onmouseover' event in your chart.  Since there really is only one actual tooltip element, and the contents will be populated by your custom tooltip text, what you could do is just specify a div with an id like this, using a view where you set the columns:  

    var myDataView = new google.visualization.DataView(myData);
    var columns = [ .. other columns ];

    columns.push({
        type: 'string',
        role: 'tooltip',
        properties: {html: true},
        calc: function(data, row) {
            var s = String(data.getValue(row, 1));
            return '<div id="tooltip_chart_div"' + 
                ' style="width: 175px; height: 150px"></div>';
        }
    });

    myDataView.setColumns(columns);

Then in your 'onmousover' handler, you can do something like this to display a BarChart in the div:

    var container = document.getElementById('tooltip_chart_div');
    if (!container) { return }

    var tooltipChart = new google.visualization.BarChart(container);
    ...
    tooltipChart.draw(barData, barOptions);

Hope that helps.




--
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-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.
To view this discussion on the web visit https://groups.google.com/d/msgid/google-visualization-api/f5ddf401-b3a1-4bd2-9a7f-5760bf9e8eed%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.



--
dlaliberte@Google.com   5CC, Cambridge MA
daniel.laliberte@GMail.com 9 Juniper Ridge Road, Acton MA
Reply all
Reply to author
Forward
0 new messages