| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697 |
- <template>
- <div :class="className" :style="{height:height,width:width}"></div>
- </template>
- <script>
- import echarts from 'echarts'
- // require('echarts/theme/macarons') // echarts theme
- export default {
- props: {
- className: {
- type: String,
- default: 'chart'
- },
- width: {
- type: String,
- default: '100%'
- },
- height: {
- type: String,
- default: '240px'
- },
- chartData: {
- type: Object
- }
- // autoResize: {
- // type: Boolean,
- // default: true
- // }
- },
- data() {
- return {
- chart: null
- }
- },
- watch: {
- chartData: {
- deep: true,
- handler: function(val) {
- if (!this.chart) {
- return false
- }
- let chartData = JSON.parse(JSON.stringify(val))
- this.setOptions(chartData)
- }
- }
- },
- mounted() {
- // this.initChart()
- },
- methods: {
- initChart() {
- let data = {
- date: ['6.15', '6.16', '6.17', '6.18', '6.19', '6.20', '6.21'],
- // accessNum: [10, 332, 301, 50, 390, 80, 320],
- guestNum: [10, 332, 301, 50, 390, 80, 320]
- }
- // this.chart = echarts.init(this.$el, 'macarons')
- this.chart = echarts.init(this.$el)
- let chartData = JSON.parse(JSON.stringify(this.chartData))
- // this.setOptions(chartData)
- this.setOptions(data)
- },
- setOptions(chartData) {
- this.chart.setOption({
- tooltip: {
- trigger: 'item',
- formatter: '{a} <br/>{b} : {c} ({d}%)'
- },
- legend: {
- orient: 'vertical',
- left: 'right',
- data: ['门店 50% 158', '微信朋友圈 33.33% 134', '美团 16.67% 24']
- },
- series: [
- {
- name: '访问来源',
- type: 'pie',
- radius: '70%',
- center: ['40%', '50%'],
- data: [{ value: 335, name: '门店 50% 158' }, { value: 310, name: '微信朋友圈 33.33% 134' }, { value: 234, name: '美团 16.67% 24' }],
- emphasis: {
- itemStyle: {
- shadowBlur: 10,
- shadowOffsetX: 0,
- shadowColor: 'rgba(0, 0, 0, 0.5)'
- }
- }
- }
- ]
- })
- }
- },
- filters: {}
- }
- </script>
|