shawnbot / topogram

Continuous area cartograms with d3 and TopoJSON
MIT License
326 stars 131 forks source link

I'm trying to read data not from .csv, but i have no idea. #24

Closed ghost closed 8 years ago

ghost commented 8 years ago

for example ,can I use static data in the .html file?

shawnbot commented 8 years ago

Hi @smilefishes, yes! You can bring your own data in any format. The key is in providing the right "value" accessor:

var cartogram = d3.cartogram()
  .value(function(feature) {
    // return a value for each feature here
  });

For instance, if you have your data in JSON as an object that maps feature IDs to numeric values, you could do this:

var data = {
  AL: 20,
  CA: 100,
  FL: 50
  // ...
};
cartogram.value(function(feature) {
  return data[feature.id] || 0;
});

Feel free to re-open this issue with a more specific question if you still need help.

ghost commented 8 years ago

thanks a lot! It really works!