Skip to content

Commit

Permalink
Add Reactive Data to charts (epicmaxco#184)
Browse files Browse the repository at this point in the history
* make charts data reactive
* fixing footer
* test
* reactive prop
* footer
  • Loading branch information
vlad-shusterman authored and asvae committed Apr 27, 2018
1 parent a1205e9 commit b05dd40
Show file tree
Hide file tree
Showing 10 changed files with 40 additions and 43 deletions.
15 changes: 5 additions & 10 deletions src/components/statistics/charts/Charts.vue
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,20 @@
<div class="row">
<div class="col-md-6">
<vuestic-widget class="chart-widget" :headerText="'charts.verticalBarChart' | translate">
<vuestic-chart v-bind:data="verticalBarChartData" type="vertical-bar"></vuestic-chart>
<vuestic-chart :data="verticalBarChartData" type="vertical-bar"></vuestic-chart>
</vuestic-widget>
</div>
<div class="col-md-6">
<vuestic-widget class="chart-widget" :headerText="'charts.horizontalBarChart' | translate">
<vuestic-chart v-bind:data="horizontalBarChartData" type="horizontal-bar"></vuestic-chart>
<vuestic-chart :data="horizontalBarChartData" type="horizontal-bar"></vuestic-chart>
</vuestic-widget>
</div>
</div>

<div class="row">
<div class="col-md-12">
<vuestic-widget class="chart-widget" :headerText="'charts.lineChart' | translate">
<vuestic-chart v-bind:data="lineChartData" type="line"></vuestic-chart>
<vuestic-chart :data="lineChartData" type="line"></vuestic-chart>
</vuestic-widget>
</div>
</div>
Expand All @@ -29,15 +29,15 @@
</div>
<div class="col-md-6">
<vuestic-widget class="chart-widget" :headerText="'charts.donutChart' | translate">
<vuestic-chart v-bind:data="donutChartData" type="donut"></vuestic-chart>
<vuestic-chart :data="donutChartData" type="donut"></vuestic-chart>
</vuestic-widget>
</div>
</div>

<div class="row">
<div class="col-md-12">
<vuestic-widget class="chart-widget" :headerText="'charts.bubbleChart' | translate">
<vuestic-chart v-bind:data="bubbleChartData" type="bubble"></vuestic-chart>
<vuestic-chart :data="bubbleChartData" type="bubble"></vuestic-chart>
</vuestic-widget>
</div>
</div>
Expand Down Expand Up @@ -65,11 +65,6 @@
horizontalBarChartData: HorizontalBarChartData
}
},
// created () {
// setInterval(() => {
// this.data.datasets.x[0] += 10
// }, 4000)
// }
}
</script>

Expand Down
2 changes: 1 addition & 1 deletion src/data/charts/LineChartData.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,5 @@ export default {
borderColor: palette.transparent,
data: [50, 20, 70, 30, 10, 5, 70]
}
]
],
}
2 changes: 1 addition & 1 deletion src/data/charts/VerticalBarChartData.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ export default {
label: 'USA',
backgroundColor: palette.primary,
borderColor: palette.transparent,
data: [40, 20, 12, 39, 10, 40, 39, 80, 40, 20, 12, 11]
data: [50, 20, 12, 39, 10, 40, 39, 80, 40, 20, 12, 11]
},
{
label: 'USSR',
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
<template>
<div class='vuestic-chart'>
<pie-chart :options="options" :data="data" v-if="type === 'pie'"></pie-chart>
<donut-chart :options="options" :data="data" v-if="type === 'donut'"></donut-chart>
<bubble-chart :options="options" :data="data" v-if="type === 'bubble'"></bubble-chart>
<line-chart :options="options" :data="data" v-if="type === 'line'"></line-chart>
<horizontal-bar-chart :options="options" :data="data" v-if="type === 'horizontal-bar'"></horizontal-bar-chart>
<vertical-bar-chart :options="options" :data="data" v-if="type === 'vertical-bar'"></vertical-bar-chart>
<pie-chart :options="options" :chart-data="data" v-if="type === 'pie'"></pie-chart>
<donut-chart :options="options" :chart-data="data" v-if="type === 'donut'"></donut-chart>
<bubble-chart :options="options" :chart-data="data" v-if="type === 'bubble'"></bubble-chart>
<line-chart :options="options" :chart-data="data" v-if="type === 'line'"></line-chart>
<horizontal-bar-chart :options="options" :chart-data="data" v-if="type === 'horizontal-bar'"></horizontal-bar-chart>
<vertical-bar-chart :options="options" :chart-data="data" v-if="type === 'vertical-bar'"></vertical-bar-chart>
</div>
</template>

Expand All @@ -27,7 +27,7 @@
HorizontalBarChart,
DonutChart,
BubbleChart
}
},
}
</script>

Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import { Bubble } from 'vue-chartjs'
import { Bubble, mixins } from 'vue-chartjs'
import DefaultOptions from '../DefaultOptions'

export default Bubble.extend({
props: ['data', 'options'],
mixins: [mixins.reactiveProp],
props: ['chartData', 'options'],

data () {
return {
Expand All @@ -14,6 +15,6 @@ export default Bubble.extend({

mounted () {
let options = Object.assign({}, DefaultOptions, this.defaultOptions, this.options)
this.renderChart(this.data, options)
this.renderChart(this.chartData, options)
}
})
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import { Doughnut } from 'vue-chartjs'
import { Doughnut, mixins } from 'vue-chartjs'
import DefaultOptions from '../DefaultOptions'

export default Doughnut.extend({
props: ['data', 'options'],
mixins: [mixins.reactiveProp],
props: ['chartData', 'options'],

data () {
return {
Expand All @@ -14,6 +15,6 @@ export default Doughnut.extend({

mounted () {
let options = Object.assign({}, DefaultOptions, this.defaultOptions, this.options)
this.renderChart(this.data, options)
this.renderChart(this.chartData, options)
}
})
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import { HorizontalBar } from 'vue-chartjs'
import { HorizontalBar, mixins } from 'vue-chartjs'
import DefaultOptions from '../DefaultOptions'

export default HorizontalBar.extend({
mixins: [mixins.reactiveProp],
props: ['data', 'options'],

data () {
Expand All @@ -14,6 +15,6 @@ export default HorizontalBar.extend({

mounted () {
let options = Object.assign({}, DefaultOptions, this.defaultOptions, this.options)
this.renderChart(this.data, options)
this.renderChart(this.chartData, options)
}
})
Original file line number Diff line number Diff line change
@@ -1,19 +1,18 @@
import { Line } from 'vue-chartjs'
import {Line, mixins} from 'vue-chartjs'
import DefaultOptions from '../DefaultOptions'

export default Line.extend({
props: ['data', 'options'],

props: ['chartData', 'options'],
mixins: [mixins.reactiveProp],
data () {
return {
defaultOptions: {

}
defaultOptions: {}
}
},


mounted () {
let options = Object.assign({}, DefaultOptions, this.defaultOptions, this.options)
this.renderChart(this.data, options)
this.renderChart(this.chartData, options)
}
})
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import {Pie} from 'vue-chartjs'
import {Pie, mixins} from 'vue-chartjs'
import DefaultOptions from '../DefaultOptions'

export default Pie.extend({
props: ['data', 'options'],
mixins: [mixins.reactiveProp],
props: ['chartData', 'options'],

data () {
return {
Expand All @@ -12,6 +13,6 @@ export default Pie.extend({

mounted () {
let options = Object.assign({}, DefaultOptions, this.defaultOptions, this.options)
this.renderChart(this.data, options)
this.renderChart(this.chartData, options)
}
})
Original file line number Diff line number Diff line change
@@ -1,19 +1,18 @@
import { Bar } from 'vue-chartjs'
import {Bar, mixins} from 'vue-chartjs'
import DefaultOptions from '../DefaultOptions'

export default Bar.extend({
props: ['data', 'options'],
mixins: [mixins.reactiveProp],
props: ['chartData', 'options'],

data () {
return {
defaultOptions: {

}
defaultOptions: {}
}
},

mounted () {
let options = Object.assign({}, DefaultOptions, this.defaultOptions, this.options)
this.renderChart(this.data, options)
this.renderChart(this.chartData, options)
}
})

0 comments on commit b05dd40

Please sign in to comment.