lime-echart.vue 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. <template>
  2. <view >
  3. <view style="height: 750rpx; background-color: aquamarine;">
  4. <l-echart ref="chart" @finished="init"></l-echart>
  5. </view>
  6. </view>
  7. </template>
  8. <script>
  9. // nvue 不需要引入
  10. // #ifdef VUE2
  11. import * as echarts from '@/uni_modules/lime-echart/static/echarts.min';
  12. // #endif
  13. // #ifdef VUE3
  14. // #ifdef MP
  15. // 由于vue3 使用vite 不支持umd格式的包,小程序依然可以使用,但需要使用require
  16. const echarts = require('../../static/echarts.min');
  17. // #endif
  18. // #ifndef MP
  19. // 由于 vue3 使用vite 不支持umd格式的包,故引入npm的包
  20. import * as echarts from 'echarts/dist/echarts.esm';
  21. // #endif
  22. // #endif
  23. export default {
  24. data() {
  25. return {
  26. option: {
  27. tooltip: {
  28. trigger: 'axis',
  29. // shadowBlur: 0,
  30. textStyle: {
  31. textShadowBlur : 0
  32. }
  33. },
  34. legend: {
  35. data: ['邮件营销', '联盟广告', '视频广告', '直接访问', '搜索引擎']
  36. },
  37. grid: {
  38. left: '3%',
  39. right: '4%',
  40. bottom: '3%',
  41. containLabel: true
  42. },
  43. xAxis: {
  44. type: 'category',
  45. boundaryGap: false,
  46. data: ['周一', '周二', '周三', '周四', '周五', '周六', '周日']
  47. },
  48. yAxis: {
  49. type: 'value'
  50. },
  51. series: [
  52. {
  53. name: '邮件营销',
  54. type: 'line',
  55. stack: '总量',
  56. data: [120, 132, 101, 134, 90, 230, 210]
  57. },
  58. {
  59. name: '联盟广告',
  60. type: 'line',
  61. stack: '总量',
  62. data: [220, 182, 191, 234, 290, 330, 310]
  63. },
  64. {
  65. name: '视频广告',
  66. type: 'line',
  67. stack: '总量',
  68. data: [150, 232, 201, 154, 190, 330, 410]
  69. },
  70. {
  71. name: '直接访问',
  72. type: 'line',
  73. stack: '总量',
  74. data: [320, 332, 301, 334, 390, 330, 320]
  75. },
  76. {
  77. name: '搜索引擎',
  78. type: 'line',
  79. stack: '总量',
  80. data: [820, 932, 901, 934, 1290, 1330, 1320]
  81. }
  82. ]
  83. }
  84. }
  85. },
  86. methods: {
  87. init() {
  88. this.$refs.chart.init(echarts, chart => {
  89. chart.setOption(this.option);
  90. console.log('res::::')
  91. });
  92. },
  93. save() {
  94. this.$refs.chart.canvasToTempFilePath({
  95. success(res) {
  96. console.log('res::::', res)
  97. }
  98. })
  99. }
  100. }
  101. }
  102. </script>