Skip to content

Instantly share code, notes, and snippets.

@barongun
Created June 13, 2018 09:13
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 barongun/7353909db0099b2527d7284366e05178 to your computer and use it in GitHub Desktop.
Save barongun/7353909db0099b2527d7284366e05178 to your computer and use it in GitHub Desktop.
echart 로 라인차트 구현하기
<template>
<e-charts :options="lineOptions"/>
</template>
<script>
import ECharts from 'vue-echarts'
import 'echarts/lib/chart/line'
import 'echarts/lib/component/tooltip'
let vm
export default {
name: 'chart-bar',
components: {ECharts},
created () {
vm = this
setInterval(function () {
vm.$store.dispatch('chart/addData', {
chartName: vm.chartName,
data: {x: Math.random(), y: Math.random()}
})
}, 1000)
},
methods: {},
computed: {
lineOptions () {
return this.$store.getters['chart/lineOptions'](this.chartName)
}
},
data: function () {
return {
chartName: 'chart1'
}
}
}
</script>
<style scoped>
</style>
import {INCREMENT_CHART_VALUE} from './mutation-types'
export const state = () => ({
chart1: {
x: [],
y: []
}
})
export const actions = {
async addData ({ commit, state }, param) {
await commit('INCREMENT_CHART_VALUE', param)
}
}
export const mutations = {
[INCREMENT_CHART_VALUE] (state, param) {
state[param.chartName].x.push(param.data.x)
state[param.chartName].y.push(param.data.y)
}
}
export const getters = {
lineOptions: (state) => (chartName) => {
return {
xAxis: {
data: state[chartName].x,
type: 'category'
},
tooltip: {},
yAxis: {
type: 'value'
},
series: [{
data: state[chartName].y,
type: 'line',
smooth: false
}]
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment