Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
ghost opened this issue Dec 15, 2015 · 2 comments
Closed

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

ghost opened this issue Dec 15, 2015 · 2 comments

Comments

@ghost
Copy link

ghost commented Dec 15, 2015

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

@shawnbot
Copy link
Owner

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
Copy link
Author

ghost commented May 4, 2016

thanks a lot! It really works!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant