Database Reference
In-Depth Information
(attr "transform" (str "translate(0," height \)))
(call x-axis)))
(defn build-y-axis [svg y-axis]
(.. svg (append "g")
(attr "class" "y axis")
(call y-axis)
(append "text")
(attr "transform" "rotate(-90)")
(attr "y" 6)
(attr "dy" ".71em")
(style "text-anchor" "end")
(text "Price ($)")))
12. The last part of the graph that we'll deal with here is the line that traces out the
data's values:
(defn add-line [svg line data]
(.. svg (append "path")
(datum data)
(attr "class" "line")
(attr "d" line)))
13. Now, we'll assemble all of these together to create the graph, as shown here:
(defn ^:export ibm-stock []
(let [margin {:top 20, :right 20, :bottom 30, :left 50}
[width height] (get-dimensions margin)
parse-date (.. js/d3 -time (format "%d-%b-%y") -parse)
[x y] (get-scales width height)
[x-axis y-axis] (get-axes x y)
line (get-line x y)
svg (get-svg margin width height)]
(.csv js/d3
"/ibm-stock/data.csv"
(fn [error data]
(.forEach data
#(coerce-datum parse-date %))
(set-domains x y data)
(build-x-axis height svg x-axis)
(build-y-axis svg y-axis)
(add-line svg line data)))))
 
Search WWH ::




Custom Search