Created
June 8, 2016 00:13
-
-
Save edwthomas/b1f653405e2827357133f7e3c245bea0 to your computer and use it in GitHub Desktop.
Example of using Chart.js with Clojurescript
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(:require [re-frame.core :as re-frame] | |
[reagent.core :as reagent] | |
[cljsjs.chartjs]) | |
(defn show-revenue-chart | |
[] | |
(let [context (.getContext (.getElementById js/document "rev-chartjs") "2d") | |
chart-data {:type "bar" | |
:data {:labels ["2012" "2013" "2014" "2015" "2016"] | |
:datasets [{:data [5 10 15 20 25] | |
:label "Rev in MM" | |
:backgroundColor "#90EE90"} | |
{:data [3 6 9 12 15] | |
:label "Cost in MM" | |
:backgroundColor "#F08080"}]}}] | |
(js/Chart. context (clj->js chart-data)))) | |
(defn rev-chartjs-component | |
[] | |
(reagent/create-class | |
{:component-did-mount #(show-revenue-chart) | |
:display-name "chartjs-component" | |
:reagent-render (fn [] | |
[:canvas {:id "rev-chartjs" :width "700" :height "380"}])})) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thanks for this - worked perfectly.