Reputation: 37
Here is the content in geojson file
{
"type": "FeatureCollection",
"features": [{
"type": "Feature",
"properties": {
"profit": 326,
"npa": 174.000000
}
}, {
"type": "Feature",
"properties": {
"profit": 1762,
"npa": 1683.000000
}
}]
}
I am storing the data in a myfile.geojson. I want to give this local geojson file as an input and display the pie chart based on the value profit. Thanks in advance
Here is the link to fiddle in which pie chart is displayed, the data of geojson file was directly stored in a variable and plotted the pie chart.
Upvotes: 0
Views: 195
Reputation: 3112
Use d3.json
to read in geojson. In your js, call d3.json with the following:
d3.json("myfile.geojson", function(error, data) {
if (error) throw error;
pie_ready_data = data.features;
console.log(pie_ready_data)
// Set up the pie chart
pie(pie_ready_data);
// Now draw the DOM objects
});
Using data.features
ensures that the pie
variable is passed an array of features
See this Plunk for the full example (including myfile.geojson as an external data source): http://plnkr.co/edit/Kvf3wK3twOGfUhix5yuZ
Upvotes: 0