pieChart.vue 1.7 KB
Newer Older
P
Pan 已提交
1
<template>
P
Pan 已提交
2
  <div :class="className" :style="{height:height,width:width}"></div>
P
Pan 已提交
3
</template>
P
Pan 已提交
4

P
Pan 已提交
5
<script>
P
Pan 已提交
6 7
import echarts from 'echarts'
require('echarts/theme/macarons') // echarts 主题
P
Pan 已提交
8

P
Pan 已提交
9 10 11 12 13
export default {
  props: {
    className: {
      type: String,
      default: 'chart'
P
Pan 已提交
14
    },
P
Pan 已提交
15 16 17
    width: {
      type: String,
      default: '100%'
P
Pan 已提交
18
    },
P
Pan 已提交
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41
    height: {
      type: String,
      default: '300px'
    }
  },
  data() {
    return {
      chart: null
    }
  },
  mounted() {
    this.initChart()
  },
  beforeDestroy() {
    if (!this.chart) {
      return
    }
    this.chart.dispose()
    this.chart = null
  },
  methods: {
    initChart() {
      this.chart = echarts.init(this.$el, 'macarons')
P
Pan 已提交
42

P
Pan 已提交
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63
      this.chart.setOption({
        title: {
          text: 'WEEKLY WRITE ARTICLES',
          x: 'center'
        },
        tooltip: {
          trigger: 'item',
          formatter: '{a} <br/>{b} : {c} ({d}%)'
        },
        legend: {
          x: 'center',
          y: 'bottom',
          data: ['industries', 'technology', 'forex', 'gold', 'forecasts', 'markets']
        },
        calculable: true,
        series: [
          {
            name: 'WEEKLY WRITE ARTICLES',
            type: 'pie',
            roseType: 'radius',
            data: [
P
Pan 已提交
64 65 66 67 68 69
              { value: 320, name: 'industries' },
              { value: 240, name: 'technology' },
              { value: 149, name: 'forex' },
              { value: 100, name: 'gold' },
              { value: 59, name: 'forecasts' },
              { value: 49, name: 'markets' }
P
Pan 已提交
70 71 72 73 74 75
            ],
            animationEasing: 'cubicInOut',
            animationDuration: 2600
          }
        ]
      })
P
Pan 已提交
76
    }
P
Pan 已提交
77
  }
P
Pan 已提交
78 79
}
</script>