Skip to content

Instantly share code, notes, and snippets.

@ELepolt
Created July 26, 2017 21:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ELepolt/a8ce7d161b0d98c26f1b14b6ed2cf16e to your computer and use it in GitHub Desktop.
Save ELepolt/a8ce7d161b0d98c26f1b14b6ed2cf16e to your computer and use it in GitHub Desktop.
ember-cli-chart
import Ember from 'ember';
export default Ember.Controller.extend({
options: {
responsive: false
},
pieValue1: 300,
pieValue2: 50,
pieValue3: 100,
pieData: Ember.computed('pieValue1', 'pieValue2', 'pieValue3', function(){
return {
labels: ['Red', "Green", "Yellow"],
datasets: [
{
data: [
parseInt(this.get('pieValue1')),
parseInt(this.get('pieValue2')),
parseInt(this.get('pieValue3'))
],
backgroundColor: ["#F7464A", "#46BFBD", "#FDB45C"],
hoverBackgroundColor: ["#FF5A5E", "#5AD3D1", "#FFC870"]
}
]
};
}),
lineValue1: 65,
lineValue2: 59,
lineLabel: "July",
lineData: Ember.computed('lineValue1', 'lineValue2', 'lineLabel', function(){
var labels = ["January", "February", "March", "April", "May", "June"];
labels.push( this.get('lineLabel') );
return {
labels: labels,
datasets: [
{
label: "My First dataset",
backgroundColor: "rgb(54, 162, 235)",
borderColor: "rgb(54, 162, 235)",
fill: false,
data: [parseInt(this.get('lineValue1')), parseInt(this.get('lineValue2')), 80, 81, 56, 55, 40]
},
{
fill: false,
label: "My Second dataset",
backgroundColor: "rgb(75, 192, 192)",
borderColor: "rgb(75, 192, 192)",
data: [28, 48, 40, 19, 86, 27, 90]
}
]
};
}),
barData: {
labels: ["January", "February", "March", "April", "May", "June", "July"],
datasets: [
{
label: "My First dataset",
fillColor: "rgba(220,220,220,0.5)",
strokeColor: "rgba(220,220,220,0.8)",
highlightFill: "rgba(220,220,220,0.75)",
highlightStroke: "rgba(220,220,220,1)",
data: [65, 59, 80, 81, 56, 55, 40]
},
{
label: "My Second dataset",
fillColor: "rgba(151,187,205,0.5)",
strokeColor: "rgba(151,187,205,0.8)",
highlightFill: "rgba(151,187,205,0.75)",
highlightStroke: "rgba(151,187,205,1)",
data: [28, 48, 40, 19, 86, 27, 90]
}
]
},
radarData: {
labels: ["Eating", "Drinking", "Sleeping", "Designing", "Coding", "Cycling", "Running"],
datasets: [
{
label: "My First dataset",
fillColor: "rgba(220,220,220,0.2)",
strokeColor: "rgba(220,220,220,1)",
pointColor: "rgba(220,220,220,1)",
pointStrokeColor: "#fff",
pointHighlightFill: "#fff",
pointHighlightStroke: "rgba(220,220,220,1)",
data: [65, 59, 90, 81, 56, 55, 40]
},
{
label: "My Second dataset",
fillColor: "rgba(151,187,205,0.2)",
strokeColor: "rgba(151,187,205,1)",
pointColor: "rgba(151,187,205,1)",
pointStrokeColor: "#fff",
pointHighlightFill: "#fff",
pointHighlightStroke: "rgba(151,187,205,1)",
data: [28, 48, 40, 19, 96, 27, 100]
}
]
},
polarAreaData: {
datasets: [{
data: [
11,
16,
7,
3,
14
],
backgroundColor: [
"#FF6384",
"#4BC0C0",
"#FFCE56",
"#E7E9ED",
"#36A2EB"
],
label: 'My dataset' // for legend
}],
labels: [
"Red",
"Green",
"Yellow",
"Grey",
"Blue"
]
}
});
<h2 id='title'>Testing the ChartJS Component</h2>
<div>
<h3>Line Chart</h3>
{{ember-chart type='line' data=lineData width="600" height="200" options=options}}
</div>
<div>
<h3>Line Chart Data Update</h3>
<ul>
<li>{{input value=lineValue1 type="number"}}</li>
<li>{{input value=lineValue2 type="number"}}</li>
</ul>
</div>
<div>
<h3>Line Chart Label Update</h3>
<ul>
<li>{{input value=lineLabel type="text"}}</li>
</ul>
</div>
<div>
<h3>Pie Chart</h3>
{{ember-chart type='pie' data=pieData width="200" height="200" options=options}}
</div>
<div>
<h3>Pie Chart Update</h3>
<ul>
<li>{{input value=pieValue1 type="number"}}</li>
<li>{{input value=pieValue2 type="number"}}</li>
<li>{{input value=pieValue3 type="number"}}</li>
</ul>
</div>
<div>
<h3>Doughnut Chart with Legend</h3>
{{ember-chart type='doughnut' data=pieData width=200 height=200 options=options}}
</div>
<div>
<h3>Bar Chart</h3>
{{ember-chart type='bar' data=barData width=600 height=200 options=options}}
</div>
<div>
<h3>Radar Chart</h3>
{{ember-chart type='radar' data=radarData width=400 height=400 options=options}}
</div>
<div>
<h3>Polar Area Chart</h3>
{{ember-chart type='polarArea' data=polarAreaData width=400 height=400 options=options}}
</div>
{{outlet}}
{
"version": "0.12.1",
"EmberENV": {
"FEATURES": {}
},
"options": {
"use_pods": false,
"enable-testing": false
},
"dependencies": {
"jquery": "https://cdnjs.cloudflare.com/ajax/libs/jquery/1.11.3/jquery.js",
"ember": "2.12.0",
"ember-template-compiler": "2.12.0",
"ember-testing": "2.12.0"
},
"addons": {
"ember-data": "2.12.1",
"ember-cli-chart": "3.3.1"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment