我试图在谷歌图表中调整这个例子。为re-frame
框架,reagent
. 我想根据订阅创建一个实时图表。我用一个简单的计数器 =+-1 进行了测试。
我得到错误: Assert failed: Render must be a function, not nil
(ifn? render-fun)
。
(defn draw-demo-chart
[d]
(let [[columns vectors options chart] (r/children d)
data (new js/google.visualization.DataTable)]
(doall ;gotta keep the doall on maps. lazy sequence...
(map (fn [[type name]]
(.addColumn data type name)) columns))
(.addRows data vectors)
(.draw chart data options)
(.load js/google "visualization" "1" (clj->js {:packages ["corechart" "orgchart" "calendar" "map" "geochart"]}))
(.setOnLoadCallback js/google draw-demo-chart)
))
(defn draw-demo-chart-container
[]
(let [count (re-frame/subscribe [:count])
columns (reaction [["date" "X"] ["number" "Y"]])
vectors (reaction (clj->js [[(new js/Date "07/11/14") 145] [(new js/Date "07/12/14") 15]
[(new js/Date "07/13/14") 23] [(new js/Date "07/14/14") 234]]))
options (reaction (clj->js {:title (str @count)}))
chart (reaction (new js/google.visualization.LineChart (.getElementById js/document "linechart"))) ]
(fn []
[draw-demo-graph @columns @vectors @options @chart])))
(def draw-demo-graph
(r/create-class {:reagent-render draw-demo-chart
:component-did-mount draw-demo-chart
:component-did-update draw-demo-chart}))