doublePie.vue 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. <!--基础折线图-->
  2. <template>
  3. <div ref="myEcharts" :style="{ height, width }"></div>
  4. </template>
  5. <script>
  6. import { ref, onMounted, nextTick, watch, getCurrentInstance } from 'vue'
  7. import * as echarts from 'echarts'
  8. export default {
  9. name: 'baseBar',
  10. props: {
  11. width: {
  12. type: String,
  13. default: '100%',
  14. },
  15. height: {
  16. type: String,
  17. default: '100%',
  18. },
  19. doublePieData: {
  20. type: Object,
  21. default: () => { },
  22. },
  23. title: {
  24. type: String,
  25. default: '',
  26. },
  27. },
  28. setup (props) {
  29. const myEcharts = ref(null)
  30. let { proxy } = getCurrentInstance()
  31. const chart = new InitChart(props, myEcharts)
  32. onMounted(() => {
  33. chart.init(props.doublePieData, proxy)
  34. })
  35. watch(
  36. props,
  37. (nweProps) => {
  38. nextTick(() => {
  39. nweProps ? chart.init(props.doublePieData, proxy) : ''
  40. })
  41. },
  42. { immediate: true, deep: true }
  43. )
  44. return {
  45. myEcharts,
  46. }
  47. },
  48. }
  49. class InitChart {
  50. constructor(props, myEcharts) {
  51. this.props = props
  52. this.myEcharts = myEcharts
  53. this.state = {
  54. chart: null,
  55. }
  56. }
  57. init (datas, proxy) {
  58. // var color = ['#55E6C1 ', '#25CCF7', '#F97F51', '#ff7675', '#5352ed', '#D6A2E8']
  59. // var data = [
  60. // { value: 9, name: '已完成' },
  61. // { value: 33, name: '进行中' },
  62. // { value: 82, name: '未完成' },
  63. // ]
  64. console.log(datas, 'double调用')
  65. this.state.chart && this.destory()
  66. this.state.chart = echarts.init(this.myEcharts.value)
  67. this.state.chart.setOption({
  68. color: datas.color ? datas.color : '',
  69. tooltip: datas.tooltip ? datas.tooltip : {
  70. trigger: 'item',
  71. formatter: '{a} <br/>{b}: {c} ({d}%)',
  72. },
  73. legend: datas.legend ? datas.legend : {},
  74. series: datas.series ? datas.series : [],
  75. })
  76. window.addEventListener('resize', () => {
  77. this.state.chart.resize()
  78. })
  79. }
  80. destory () {
  81. this.state.chart.dispose()
  82. window.removeEventListener('resize', () => {
  83. console.log('事件移除')
  84. })
  85. }
  86. }
  87. </script>
  88. <style lang="less"></style>