Implementing a graph in clojurescript

65 views Asked by At

I have been trying to implement a graph in clojurescript , I am using c3.js library for the implementation and it’s failing to render the graph , I earlier got errors wrt c3.generate(), but even after resolving them the graph doesn’t show up


(defn new-chart[] 
  (println"Inside new chart ") 
  (let [c3-version (.-version js/c3)
        _ (println c3-version) 
        config-map {:bindto "#chart"
                    :data {:columns
                           [["data1" 30 200 100 400 150 150]
                            ["data2" 50 20 10 40 15 25]]
                           } } 
           _ (println "Config map "config-map) 
         myjs (clj->js config-map)]
        
(.generate js/c3 myjs)))

(defn rev-chartjs-component [] 
  (reagent/create-class {:component-did-mount #(new-chart)
                         :display-name "chartjs-component"
                         :reagent-render (fn []
                                           (println "Inside render function")
                                           [:canvas {:id "#chart" :width "700" :height "380"}])}))

[rev-chartjs-component] ;;this is called inside a [:div]

1

There are 1 answers

0
Thomas Heller On

Kinda hard to answer without more context, but one mistake I see is using [:canvas {:id "#chart"} ..., which should not have a #. The # is part of the selector syntax to get elements by id, it is not part of the actual id.

Either way you should be getting an error message in the Browser Console, which should provide more info on what is going wrong.