当前位置:   article > 正文

uniapp 微信小程序端echarts扇形图_uni 扇形统计

uni 扇形统计

 github地址:https://github.com/yah0130/echarts-wx-uniapp

插件地址:echarts-for-wx - DCloud 插件市场

具体流程参考github或者插件文档

 效果图

 主要代码:

  1. <template>
  2. <view>
  3. <uni-ec-canvas class="uni-ec-canvas" id="uni-ec-canvas" ref="canvas" canvas-id="uni-ec-canvas" :ec="ec">
  4. </uni-ec-canvas>
  5. </view>
  6. </template>
  7. <script>
  8. import uniEcCanvas from '@/pagesIndex/components/uni-ec-canvas/uni-ec-canvas.vue'
  9. import * as echarts from '@/pagesIndex/components/uni-ec-canvas/echarts'
  10. let chart = null
  11. export default {
  12. components: {
  13. uniEcCanvas
  14. },
  15. data() {
  16. return {
  17. ec: {
  18. lazyLoad: true
  19. },
  20. option: {
  21. legend: {
  22. top: '0%',
  23. left: 'center',
  24. itemWidth: uni.upx2px(16), // 图例标记的图形宽度。
  25. itemHeight: uni.upx2px(16), // 图例标记的图形高度。
  26. itemGap: uni.upx2px(22), // 图例每项之间的间隔。
  27. textStyle: {
  28. color: "#000", // 文字的颜色。
  29. fontFamily: "sans-serif", // 文字的字体系列。
  30. fontSize: uni.upx2px(12), // 文字的字体大小。
  31. lineHeight: uni.upx2px(0), // 行高。
  32. },
  33. },
  34. //柱子颜色设置
  35. color: ['#78ce5e', '#fffd5e', '#F88421', '#42B1FF', '#FF5C50', '#B424D5', '#B89775', '#7D4E44',
  36. '#60AACD', '#97D6F4', '#3E6374', '#812890', '#E66520', '#D2D117', '#60594D', '#FF2C51',
  37. '#24C91D'
  38. ],
  39. series: [{
  40. name: 'Access From',
  41. type: 'pie',
  42. // radius: '70%',
  43. radius: ['30%', '65%'],
  44. avoidLabelOverlap: false,
  45. data: [
  46. { value: 1048, name: '10.80%' },
  47. { value: 735, name: '20.80%' },
  48. { value: 580, name: '5.80%' },
  49. { value: 1048, name: '30.80%' },
  50. { value: 735, name: '40.80%' },
  51. { value: 580, name: '50.80%' },
  52. { value: 1048, name: '60.80%' },
  53. { value: 735, name: '70.80%' },
  54. { value: 580, name: '80.90%' },
  55. { value: 1048, name: '10.90%' },
  56. { value: 735, name: '20.89%' },
  57. { value: 580, name: '5.90%' },
  58. { value: 1048, name: '30.90%' },
  59. { value: 735, name: '40.90%' },
  60. { value: 580, name: '50.90%' },
  61. { value: 1048, name: '60.90%' },
  62. ],
  63. label: {
  64. align: 'center',
  65. normal: {
  66. formatter: '{c}万',
  67. // position:'inner', //标签的位置
  68. color: '#000',
  69. textStyle: {
  70. fontSize: uni.upx2px(10),
  71. },
  72. },
  73. },
  74. labelLine: {
  75. normal: {
  76. length: 5,
  77. length2: 6
  78. },
  79. }
  80. }]
  81. }
  82. }
  83. },
  84. onLoad() {
  85. this.$nextTick(() => {
  86. this.$refs.canvas.init(this.initChart)
  87. })
  88. },
  89. methods: {
  90. initChart(canvas, width, height, canvasDpr) {
  91. chart = echarts.init(canvas, null, {
  92. width: width,
  93. height: height,
  94. devicePixelRatio: canvasDpr
  95. })
  96. canvas.setChart(chart)
  97. chart.setOption(this.option)
  98. console.log('setOption')
  99. return chart
  100. },
  101. }
  102. }
  103. </script>
  104. <style lang="scss">
  105. .uni-ec-canvas {
  106. width: 50%;
  107. height: 500rpx;
  108. display: block;
  109. }
  110. </style>

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/小蓝xlanll/article/detail/549710
推荐阅读