Sunday, 10 July 2016

carto - Including chart based on fields in CartoDB infowindow?


I would like to make graphs, pie charts, etc based on fields in my table within my infowindows. Is there a way to accomplish this?



Answer



In cartodb.js you have an example integration with google charts. Other charting libraries should work in the same way. You can see it working here.


The key is to call the chart function inside the infowindow template, note draw_chart call:



 var INFOWINDOW_TEMPLATE = [
'
',
' x',
'
',
'
',
'
',
'