Database Reference
In-Depth Information
How it works…
For the most part, this recipe's very similar to the preceding ones. The interesting difference
here is that we partition the data into buckets.
To do this, we get the minimum and maximum values in the data and divide the difference
between them by the number of buckets. This gives us the width of each bucket in the data.
We use this to determine which bucket each data point goes into, and we count the number
of data points in each bucket.
We also get the center value for each bucket, and we use this to label the columns in
the graph.
Creating time series charts with D3
So far in this chapter, all the charts that we've created have used a utility library, NVD3, to do
a lot of heavy lifting for us. However, we can also create a lot of these charts directly with D3.
We'll see how to do this to use graphs with time series data.
Getting ready
We'll use the same dependencies and plugins in our project.clj ile as we did in the
Creating scatter plots with NVD3 recipe. Also, we'll use the framework we created in the
recipes in this chapter upto the Creating scatter plots with NVD3 recipe.
For data, we'll use IBM's stock prices from the end of November 2001 to November 2012.
You can download this dataset from http://www.ericrochester.com/clj-data-
analysis/data/ibm.csv . Save the ile into resources/data/ibm.csv .
How to do it…
Our procedure will largely follow the pattern that we've established in the previous recipes.
However, we'll also redeine some functions to make sure that we don't load NVD3. To do this,
perform the following steps:
1. First, we'll deine a function that uses d3-page to create the page containing the
stock price graph:
(defn time-series []
(d3-page
"IBM Stock Data"
"webviz.time.ibm_stock();"
[:div#time.chart [:svg]]))
 
Search WWH ::




Custom Search