Charts 如何使用ClojureScript中的新数据更新图表列表?
我是ClojureScript的新手,我正在尝试用新数据更新图表。我正在使用图表和试剂。第一次呈现图表效果很好,但是如果我更改了ChartList函数的数据,图表将不会再次呈现。我已经尝试了原子的不同功能,并尝试使用ChartList的更新功能。这里是链接到 以下是我目前的代码:Charts 如何使用ClojureScript中的新数据更新图表列表?,charts,clojurescript,reagent,chartist.js,Charts,Clojurescript,Reagent,Chartist.js,我是ClojureScript的新手,我正在尝试用新数据更新图表。我正在使用图表和试剂。第一次呈现图表效果很好,但是如果我更改了ChartList函数的数据,图表将不会再次呈现。我已经尝试了原子的不同功能,并尝试使用ChartList的更新功能。这里是链接到 以下是我目前的代码: (ns example.core (:require [clojure.browser.repl :as repl] [reagent.core :as reagent]
(ns example.core
(:require [clojure.browser.repl :as repl]
[reagent.core :as reagent]
[cljsjs.chartist]
))
(defonce conn
(repl/connect "http://localhost:9000/repl"))
(defonce results(reagent/atom [1 1 6 15 25] ))
(defonce timespan (reagent/atom ["Mar-2012" "Jun-2012" "Nov-2012" "Oct-2013" "Nov-2014"]))
(def global-state (reagent/atom 0))
(defn show-chart
[resultsInChart timespaneInChart]
(let [chart-data {:labels timespaneInChart
:series [resultsInChart]}
options {:width "700px"
:height "380px"}]
(js/Chartist.Line. ".ct-chart" (clj->js chart-data) (clj->js options))))
(defn chart-component
[]
(let [some global-state]
(reagent/create-class
{:component-did-mount #(show-chart @results @timespan)
:component-did-update #(show-chart @results @timespan)
:display-name "chart-component"
:reagent-render (fn []
[:div {:class "ct-chart ct-perfect-fourth"}])})))
(defn home-page []
[:div
[:div
[:p [:button {:on-click #(reset! results [1 1 6 15 5]
)} "Change last Value to 5"]
]
]
]
)
(defn run []
(reagent/render [chart-component](.getElementById js/document "myChart"))
(reagent/render [home-page](.getElementById js/document "app"))
)
如果有人能帮忙就好了
更新:
我将figwheel添加到我的项目中,解决了这个问题,图表也得到了更新。最后,我还使用了组件did update下的ChartList更新功能。这里是figwheel的链接如果你将原子本身传递到
show chart
并在该函数中对其进行解引用,会发生什么?图表中没有任何内容。当值发生变化时,将调用“component did udate”,这样部件工作正常,但图表不会重新绘制。我还尝试对(show chart@results@timespan)的返回值使用函数update()或detach()。我对试剂也是新手。对我(使用NVD3图表)有效的方法是在单击函数中调用图表函数。我没有使用:组件更新了。我不理解:组件确实更新了
,但根据我的理解,在我看来,您想做的事情应该与:组件确实更新了
,如果您在显示图表
中而不是在图表组件
中对原子进行排序。在您当前的设置中,我认为原子的初始解引用值是在第一次调用图表组件
时传递的,然后在显示图表
中不再使用原子。