2

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?

4

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 = [
        '<div class="cartodb-popup v2">',
        '  <a href="#close" class="cartodb-popup-close-button close">x</a>',
        '   <div class="cartodb-popup-content-wrapper">',
        '     <div class="cartodb-popup-content">',
        '       <div id="chart_div">',
        '       <script>',
          '       draw_chart([{{content.data.pop_min}}, {{content.data.pop_max}}], "{{content.data.name}}");',
        '       </scr' + 'ipt>',
        '       </div>',
        '     </div>',
        '   </div>',
        '   <div class="cartodb-popup-tip-container"></div>',
        '</div>'].join('');
  • In your example, you're using a Json. Would it be possible to use it without? building a map from scratch like this: cartodb.createLayer(map, {user_name: 'user', type: 'cartodb', sublayers: [{sql: 'select * from table', cartocss: cssstyle, setInteractivity: 'var1','var2','var3'}] Thanks! – user28023 Feb 28 '17 at 16:08

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.