ntExtendCharts.vue 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. <template>
  2. <div :class="[className, chartsId]" style="height: 100%"></div>
  3. </template>
  4. <script>
  5. import echarts from 'echarts/lib/echarts'
  6. import { chartsInitData, chartsInitBAutoResize, chartsDestroyData, drawCharts } from './echart'
  7. export default {
  8. props: {
  9. className: {
  10. type: String,
  11. default: 'chart'
  12. },
  13. chartsId: {
  14. type: String,
  15. default: 'chart'
  16. },
  17. autoResize: {
  18. type: Boolean,
  19. default: true
  20. },
  21. type: {
  22. type: String,
  23. default: 'bar'
  24. },
  25. options: {
  26. type: Object,
  27. default: () => {}
  28. },
  29. chartData: {
  30. type: Object,
  31. default: () => {}
  32. }
  33. },
  34. data() {
  35. return chartsInitData(this.type);
  36. },
  37. mounted() {
  38. this.initChart();
  39. },
  40. beforeDestroy() {
  41. chartsDestroyData(this);
  42. },
  43. watch: {
  44. chartData: {
  45. deep: true,
  46. handler() {
  47. this.initChart()
  48. }
  49. }
  50. },
  51. methods: {
  52. initChart() {
  53. // console.log(this)
  54. if(!this.chart){
  55. this.chart = echarts.init(this.$el, this.className);
  56. chartsInitBAutoResize(this);
  57. }
  58. drawCharts(this);
  59. }
  60. }
  61. }
  62. </script>