1

I wanted to make a chopleth with d3.js in a Jekyll draft.

But somehow Jekyll is changing my JSON file from

{"type":"FeatureCollection", "features":[{"type":"Feature", "id":"01",

to

{"type"=>"FeatureCollection", "features"=>[{"type"=>"Feature", "id"=>"01",

I wanted jekyll to put my json file inside d3.json() function, like this:

d3.json({{site.data.us-states}},  function(json){
svg.selectAll("path") blah blah

where us-states is my us-states.json file but heckin Jekyll is putting everywhere =>

Is anyone able to help me?

MikolajM
  • 300
  • 1
  • 13

1 Answers1

0

site is a Jekyll global variable.

site.data is a Ruby hash containing the data loaded from the YAML files located in the _data directory.

site.data.us-states is a Ruby hash or array, I assume.

d3.json is a D3 function that fetches JSON. It does not convert a Ruby hash or array to a JavaScript object.

In Ruby, you convert a hash or array to JSON by calling to_json on it.

In JavaScript, you convert a JSON string to an object by calling JSON.parse.

Ashitaka
  • 19,028
  • 6
  • 54
  • 69