I have successfully included charts in infowindows (e.g. https://github.com/CartoDB/cartodb.js/blob/develop/examples/infowindow_with_graph.html) but I would like to include charts in panels alongside a cartodb map. Is there a way to adjust the code in the link above to achieve this?
-
Thats great Andy, Im trying to do something similar but my tables dont have numeric values, I want do draw charts on string values. For example I have a column that is divided by 3 values; inspected, not inspected and active. I would like to draw a piechart with the % of inspected, not inspected and active. Could you show me an example for doing this?? Thanks– user3826220Commented May 8, 2015 at 2:04
1 Answer
You can use click events to get the data from the object you click on and control where that data goes by using the callback object.
First put the draw_chart
function from that example in the click event below:
sublayer.on('featureClick',function(e, latlng, pos, data, subLayerIndex) {
draw_chart([data.pop_min, data.pop_max], data.name);
});
You can then edit draw_chart
to put the chart into whichever div element you want.
See a basic working example here. It uses most of the code from the example you included.
Check out the CartoDB.js documentation for more information.