From a7194b990f28c548ae228517bfe76dff3ae7ce2e Mon Sep 17 00:00:00 2001 From: Jakub Juszczak Date: Sun, 2 Oct 2016 10:32:30 +0200 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20Add=20reactive=20Data=20example?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/examples/ReactiveExample.js | 41 +++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 src/examples/ReactiveExample.js diff --git a/src/examples/ReactiveExample.js b/src/examples/ReactiveExample.js new file mode 100644 index 0000000..1f282b8 --- /dev/null +++ b/src/examples/ReactiveExample.js @@ -0,0 +1,41 @@ +import BarChart from '../BaseCharts/Bar' +import reactiveData from '../mixins/reactiveData' + +export default BarChart.extend({ + mixins: [reactiveData], + data () { + return { + chartData: '' + } + }, + created () { + this.fillData() + }, + + mounted () { + this.renderChart(this.chartData) + + setInterval(() => { + this.fillData() + }, 5000) + }, + + methods: { + fillData () { + this.chartData = { + labels: ['January' + this.getRandomInt(), 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'], + datasets: [ + { + label: 'Data One', + backgroundColor: '#f87979', + data: [this.getRandomInt(), this.getRandomInt(), this.getRandomInt(), this.getRandomInt(), this.getRandomInt(), this.getRandomInt(), this.getRandomInt(), this.getRandomInt(), this.getRandomInt(), this.getRandomInt(), this.getRandomInt(), this.getRandomInt()] + } + ] + } + }, + + getRandomInt () { + return Math.floor(Math.random() * (50 - 5 + 1)) + 5 + } + } +})