An easy interface to use all of chartjs.org's charts.
Inspired by my own pain and suffering of trying to add a simple chart to dashing
## Installation ##### 1. Import Chartjs library In `dashboards/layout.erb`, add this script tag:<script type="text/javascript" src="//cdnjs.cloudflare.com/ajax/libs/Chart.js/1.0.2/Chart.min.js"></script>
before this script tag:
<script type="text/javascript" src="/assets/application.js"></script>
Copy and paste the contents of this file into: assets/javascripts/dashing-chartjs.coffee
Then in assets/javascripts/application.coffee
, add #= require dashing-chartjs
right after #= require dashing.js
so it looks like this:
# dashing.js is located in the dashing framework
# It includes jquery & batman for you.
#= require dashing.js
#= require dashing-chartjs
Simply inherit from Dashing.Chartjs
(instead of Dashing.Widget)
class Dashing.MyCharts extends Dashing.Chartjs
Now you have access to all the functions!!!
<canvas id="myChart" width="400" height="300"></canvas>
class Dashing.Example extends Dashing.Chartjs
ready: ->
@lineChart 'myChart', # The ID of your html element
["Week 1", "Week 2", "Week 3", "Week 4", "Week 5"], # Horizontal labels
[
label: 'Number of pushups' # Text displayed when hovered
colorName: 'blue' # Color of data
data: [10, 39, 20, 49, 87] # Vertical points
]
@lineChart 'myChart', # Horizontal labels
["Week 1", "Week 2", "Week 3", "Week 4", "Week 5"],
[{
# First data points
label: 'Number of pushups'
colorName: 'blue'
data: [10, 39, 20, 49, 87]
}, {
# Second data points
label: 'Number of pullups'
colorName: 'red'
data: [3, 2, 10, 12, 20]
}
]
@lineChart(elementId, horizontalLabels, dataSets)
class Dashing.Line extends Dashing.Chartjs
ready: ->
@lineChart 'myChart',
["Week 1", "Week 2", "Week 3", "Week 4", "Week 5"],
[
label: 'Number of pushups'
colorName: 'blue'
data: [10, 39, 20, 49, 87]
]
@barChart(elementId, horizontalLabels, dataSets)
class Dashing.Bar extends Dashing.Chartjs
ready: ->
@lineChart 'myChart',
["Day 1", "Day 2", "Day 3", "Day 4", "Day 5"],
[
label: 'Customer count'
colorName: 'blue'
data: [210, 339, 220, 494, 109]
]
@radarChart(elementId, horizontalLabels, dataSets)
class Dashing.Radar extends Dashing.Chartjs
ready: ->
@radarChart 'myChart',
["Crossfit", "Yoga", "Weight Lifting", "Running", "Swimming", "Watching TV"],
[
label: 'Favorite Workout'
colorName: 'yellow'
data: [210, 339, 220, 234, 311, 494]
]
@polarAreaChart(elementId, dataSets)
class Dashing.Polar extends Dashing.Chartjs
ready: ->
@polarAreaChart("otherChart",
[{
value: 300
colorName: 'red'
label: "Red"
}, {
value: 50
colorName: 'green'
label: "Green"
}, {
value: 88
colorName: 'yellow'
label: "Yellow"
}])
@pieChart(elementId, dataSets)
class Dashing.Pie extends Dashing.Chartjs
ready: ->
@pieChart("otherChart",
[{
value: 13
colorName: 'red'
label: "Pumpkim"
}, {
value: 32
colorName: 'green'
label: "Apple"
}, {
value: 40
colorName: 'yellow'
label: "Pizza"
}, {
value: 20
colorName: 'gray'
label: "Rhubarb"
}])
@doughnutChart(elementId, dataSets)
class Dashing.Doughnut extends Dashing.Chartjs
ready: ->
@doughnutChart("otherChart",
[{
value: 20
colorName: 'green'
label: "Apple Fritter"
}, {
value: 13
colorName: 'blue'
label: "Chocolate"
}, {
value: 12
colorName: 'darkgray'
label: "Maple"
}])
blue | cyan | darkgray | gray | green | lightgray | magenta | red | yellow