BarChartPastureMonth.vue 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. <template>
  2. <div :class="className" :style="{height:height,width:width}" />
  3. </template>
  4. <script>
  5. import echarts from 'echarts'
  6. require('echarts/theme/macarons') // echarts theme
  7. import resize from './mixins/resize'
  8. // eslint-disable-next-line no-unused-vars
  9. const animationDuration = 6000
  10. export default {
  11. mixins: [resize],
  12. props: {
  13. className: {
  14. type: String,
  15. default: 'chart'
  16. },
  17. width: {
  18. type: String,
  19. default: '100%'
  20. },
  21. height: {
  22. type: String,
  23. default: '475px'
  24. }
  25. },
  26. data() {
  27. return {
  28. chart: null
  29. }
  30. },
  31. mounted() {
  32. this.$nextTick(() => {
  33. this.initChart()
  34. })
  35. },
  36. beforeDestroy() {
  37. if (!this.chart) {
  38. return
  39. }
  40. this.chart.dispose()
  41. this.chart = null
  42. },
  43. methods: {
  44. initChart() {
  45. this.chart = echarts.init(this.$el, 'macarons')
  46. this.chart.setOption({
  47. legend: {},
  48. tooltip: {},
  49. dataset: {
  50. source: [
  51. ['product', '2015', '2016', '2017'],
  52. ['10月', 43.3, 85.8, 93.7],
  53. ['9月', 83.1, 73.4, 55.1],
  54. ['8月', 86.4, 65.2, 82.5],
  55. ['7月', 72.4, 53.9, 39.1]
  56. ]
  57. },
  58. xAxis: [
  59. { type: 'category', gridIndex: 0, name: '最近12个月' }
  60. ],
  61. yAxis: [
  62. { gridIndex: 0, name: '总费用' }
  63. ],
  64. grid: [
  65. { bottom: '58%' },
  66. { top: '58%' }
  67. ],
  68. series: [
  69. { type: 'bar' },
  70. { type: 'bar' },
  71. { type: 'bar' }
  72. ]
  73. })
  74. }
  75. }
  76. }
  77. </script>