Last active
March 17, 2019 10:29
-
-
Save nagarajanpp8/a12b27d6fab0395aa8b3f98ec65643b9 to your computer and use it in GitHub Desktop.
donut-chart-with-realtime-data-update
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
import Ember from 'ember'; | |
export default Ember.Component.extend({ | |
}); |
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
import Ember from 'ember'; | |
const DefineCP = function(context, cpName, dependantKey, model, arrayIndex){ | |
context.set("model", model); | |
dependantKey = dependantKey+ ".[]"; | |
Ember.defineProperty(context, cpName, Ember.computed(dependantKey, function () { | |
return this.get(dependantKey)[arrayIndex]; | |
})); | |
}; | |
const DonutChart = Ember.Object.extend({ | |
type: "donut-chart", | |
reinit(labels){ | |
let obj = { | |
"labels": labels | |
}; | |
this.setProperties(obj); | |
let tempArray = []; | |
for(let i = 0; i < labels.length; i++){ | |
tempArray.pushObject(Ember.Object.create({"label": labels[i]})) | |
} | |
this.set("data", tempArray); | |
//console.log("donut chart obj created", tempArray); | |
return this; | |
}, | |
setData(value, model){ | |
let data = this.get("data"); | |
for(let i =0; i<data.length; i++){ | |
DefineCP(data.objectAt(i), "value", `model.${value}`, model, i); | |
} | |
return this; | |
} | |
}); | |
export default Ember.Controller.extend({ | |
appName: 'Ember Twiddle', | |
data: [2,3,4], | |
init(){ | |
this._super(...arguments); | |
let lables = ["one", "two", "three"]; | |
this.set("donutModel", DonutChart.create().reinit(lables)); | |
}, | |
donutChartData:Ember.computed(function(){ | |
return this.get("donutModel").setData("data", this.get("model")); | |
}), | |
actions:{ | |
update(){ | |
let temp = [Math.floor(Math.random() * 10) + 10, Math.floor(Math.random() * 10), Math.floor(Math.random() * 10) + 20]; | |
this.set("model.data", temp); | |
} | |
} | |
}); |
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
import EmberRouter from '@ember/routing/router'; | |
import config from './config/environment'; | |
const Router = EmberRouter.extend({ | |
location: 'none', | |
rootURL: config.rootURL | |
}); | |
Router.map(function() { | |
}); | |
export default Router; |
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
import Ember from 'ember'; | |
export default Ember.Route.extend({ | |
model(){ | |
return {"id": 1, "data": [2,4,5]}; | |
} | |
}); |
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
{ | |
"version": "0.15.1", | |
"EmberENV": { | |
"FEATURES": {} | |
}, | |
"options": { | |
"use_pods": false, | |
"enable-testing": false | |
}, | |
"dependencies": { | |
"jquery": "https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.js", | |
"ember": "2.14.1", | |
"ember-template-compiler": "2.14.1", | |
"ember-testing": "2.14.1" | |
}, | |
"addons": { | |
"ember-data": "2.14.10", | |
"ember-cli-morris-charts": "1.0.1" | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment