Skip to content

Instantly share code, notes, and snippets.

@markmarkoh markmarkoh/
Last active Aug 29, 2015

What would you like to do?
Fetching remote data with Datamaps

Remote Data with Datamaps

If you have data in CSV or JSON format on your server, you can now ( v0.2.7 ) fetch that data remotely.


To specify CSV, set dataType to "csv" and specify the dataUrl for the resource.

The format for this data should be:


You can optionally pass more data for event handlers and popupTemplate:

NY,Visited,Value for another property
TX,Visited,will be passed as `data.anotherProperty` in popupTemplate
CA,Visited,more data


JSON is the default dataType. For JSON data, just specify a dataUrl.

The payload should look something like this:

  "NY": {"fillKey": "Visited", "anotherProperty": "Born here"},
  "TX": {"fillKey": "Visited", "anotherProperty": "Live here"},
  "CA": {"fillKey": "Visited", "anotherProperty": "Here while writing this code"}
id fillKey info
NY Visited Born here
CA Visited Here while writing this code
TX Visited Live here
USA Visited Home Country
"NY": {"fillKey": "Visited", "info": "Born here"},
"TX": {"fillKey": "Visited", "info": "Live here"},
"CA": {"fillKey": "Visited", "info": "Here while writing this code"}
<!DOCTYPE html>
.active { fill: blue !important;}
/*.datamaps-key dt, .datamaps-key dd {float: none !important;}
.datamaps-key {right: -50px; top: 0;}*/
<div id="container1" style="border:1px dotted blue; width: 700px; height: 475px; position: relative;"></div>
<script src=""></script>
<script src=""></script>
<script src=""></script>
var election = new Datamap({
scope: 'usa',
element: document.getElementById('container1'),
geographyConfig: {
popupTemplate: function(geo, data) {
return data && && "<div class='hoverinfo'><strong>" + + "</strong></div>";
highlightOnHover: false,
borderColor: '#444',
borderWidth: 0.5
dataUrl: 'data.csv',
dataType: 'csv',
data: {},
fills: {
'Visited': '#306596',
'neato': '#0fa0fa',
'Trouble': '#bada55',
defaultFill: '#dddddd'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.