Reputation: 225
I'm trying to implement a d3.js histogram on my website which is getting the data from a solr response. On my research I discovered Mike Bostock who's offering great D3 solutions. One of it is the "Histogram II" which would fit perfectly for my needs. The problem is that it (and all other comparable solutions I found) comes with a .csv as data source. I would like to use an array as data source but failed as I tried to change the input.
Can you please give me a tip which lines have to be changed to use the following array, which is currently based on Mike Bostocks .csv:
my_data = [
{"id": "10097071", "case": "HY285524", "date": "06/02/2015 09:41:19 PM"},
{"id": "21907", "case": "HY291065", "date": "06/07/2015 03:50:00 AM"}
]
Thanks in advance.
Upvotes: 3
Views: 602
Reputation: 102194
In Bostock's original code, the date
strings are being parsed by the type
function, called by d3.csv
as a row function:
function type(d) {
d.date = parseDate(d.date);
return d;
}
Since you plan to use an variable to hold your data array and get rid of d3.csv
completely, you'll have to parse the date
strings some other way. For instance, you can use a forEach
:
data.forEach(function(d){
d.date = parseDate(d.date)
})
Here is the demo, I just modified Bostock's code for using an array instead of a CSV file: https://bl.ocks.org/anonymous/bb0d820fbca8fbdf0f8827b0edbcbd44. Look at the forEach
after the data
array.
Upvotes: 2