On Thu, May 03, 2012 at 12:56:48PM -0700, retro wrote:
> Can someone help me understanding the calendar example. I need to
> modify it to show data in particular date range only and possibly show
> only 1 or 3 months. What needs to be changed?
I assume you mean
http://mbostock.github.com/d3/ex/calendar.html
On line 16, you can see it creates a separate <svg> element for each
year:
.data(d3.range(1990, 2011))
So if you only wanted to show a few months for a single year, you could
change this to the year in question:
.data([2012])
Since you know there's only one year, you could also simply append the
<svg> element without using data binding:
var svg = d3.select("#chart").append("svg")
The months are chosen on line 30:
.data(function(d) {
return d3.time.days(new Date(d, 0, 1), new Date(d + 1, 0, 1));
})
Here, d3.time.days is used to generate all the days between two given
years. The starting year is retrieved from the data bound on line 16.
So if you only wanted to show a few months, you would simply modify
these two dates appropriately.
> Also, as far as reading the data is concerned, i have a json string
> with key and values
> 2008-01-01,16
>
> How can i modify the csv code to read this data as json?
I'm not sure I understand the question. You may want to read up on
d3.csv to see how CSV parsing works:
https://github.com/mbostock/d3/wiki/CSV
If you want to load the data from a JSON file, you can use d3.json:
https://github.com/mbostock/d3/wiki/Requests#wiki-d3_json
--
Jason Davies,
http://www.jasondavies.com/