1
0
Fork 0
mirror of https://git.rwth-aachen.de/acs/public/villas/web/ synced 2025-03-09 00:00:01 +01:00

Move charts to pure flotcharts.js and redraw on data change

This commit is contained in:
Markus Grigull 2015-10-09 11:35:31 +02:00
parent 1b576d543c
commit acebff7c0c
5 changed files with 39 additions and 18 deletions

View file

@ -1,17 +1,24 @@
import Ember from 'ember';
const { Component, computed } = Ember;
export default Ember.Component.extend({
tagName: 'canvas',
tagName: 'div',
classNames: ['line-chart'],
didInsertElement: function() {
// create chart
var element = this.get('element');
this.chart = new Chart(element.getContext('2d'));
this.chart.Line(this.chartData, {
init: function() {
this._super();
this.addObserver('data', this.dataDidChange);
},
});
didInsertElement: function() {
this._drawPlot();
},
dataDidChange: function() {
this._drawPlot();
},
_drawPlot: function() {
var elementId = this.get('elementId');
$.plot('#' + elementId, this.data);
}
});

View file

@ -10,9 +10,9 @@ export default Ember.Route.extend({
return record;
},
chartData() {
chartData: function() {
return {
name: 'test'
};
}
}.property()
});

View file

@ -124,9 +124,9 @@ footer {
margin: 0;
}
canvas.line-chart {
width: 90%;
height: 90%;
.line-chart {
width: 500px;
height: 300px;
margin: 10px;
}

View file

@ -1 +1,10 @@
<!-- {{#if data}}
<p>History: {{data.[0].length}}</p>
{{/if}}
<ul>
{{#each data.[0] as |sample|}}
<li>{{sample.[1]}}</li>
{{/each}}
</ul>
-->

View file

@ -1,7 +1,12 @@
{{#if property}}
<p>{{property.name}}</p>
{{#if model.name}}
<p>Model: {{model.name}}, {{model.history.[0].length}}</p>
{{/if}}
{{chartData.name}}
{{#if chartData}}
<p>{{chartData.name}}</p>
{{else}}
<p>No chart data</p>
{{/if}}
{{flot-chart height="500px" data=model.history}}
<!-- {{flot-chart height="500px" data=model.history}} -->
{{line-chart data=model.history}}