拓恒飞手平台小程序
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

97 lines
2.0KB

  1. // components/pie/index.js
  2. import * as echarts from "../ec-canvas/echarts"
  3. let chart
  4. function getPixelRation(){
  5. var {pixelRatio} = wx.getSystemInfoSync();
  6. return pixelRatio||1
  7. };
  8. function initChart(canvas, data, total) {
  9. chart = echarts.init(canvas, null, {
  10. width: 315,
  11. height: 280,
  12. devicePixelRatio:getPixelRation()
  13. })
  14. var option = getOption(data, total)
  15. chart.setOption(option)
  16. canvas.setChart(chart)
  17. return chart
  18. }
  19. function getOption(data, total) {
  20. let option = {
  21. disableTouch: true,
  22. backgroundColor: "#ffffff",
  23. title: {
  24. text: '任务总数',
  25. subtext: total + '条',
  26. textAlign: 'center',
  27. x: '48%',
  28. y: '42%'
  29. },
  30. legend: {
  31. bottom: "5%",
  32. orient: 'vertical',
  33. left: "right",
  34. selectedMode: false
  35. },
  36. grid: [
  37. {
  38. bottom: 40,
  39. top: -30,
  40. left: 5,
  41. right: 5,
  42. },
  43. ],
  44. series: [
  45. {
  46. type: 'pie',
  47. center: ['50%', '50%'],
  48. radius: ["40%", "65%"],
  49. silent: true,
  50. label: {
  51. position: 'inner',
  52. fontSize: 12,
  53. formatter: '{d}%'
  54. },
  55. labelLine: {
  56. show: false
  57. },
  58. data: data,
  59. },
  60. ]
  61. }
  62. return option
  63. }
  64. Component({
  65. /**
  66. * 组件的属性列表
  67. */
  68. properties: {
  69. data: {
  70. type: Object
  71. }
  72. },
  73. /**
  74. * 组件的初始数据
  75. */
  76. data: {
  77. ec: {
  78. onInit: initChart
  79. },
  80. },
  81. // 数据监听器
  82. observers: {
  83. data() {
  84. setTimeout(()=>{
  85. chart.setOption(getOption(this.properties.data.dataList, this.properties.data.total))
  86. },500)
  87. },
  88. },
  89. /**
  90. * 组件的方法列表
  91. */
  92. methods: {
  93. }
  94. })