pie.js 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. // 线图
  2. import * as echarts from '../../ec-canvas/echarts';
  3. Component({
  4. /**
  5. * 组件的属性列表
  6. */
  7. properties: {
  8. canvasId: {
  9. type: String,
  10. value: "mychart-dom-bar"
  11. },
  12. id: {
  13. type: String,
  14. value: "mychart-bar"
  15. },
  16. showLegend:{
  17. type: Boolean,
  18. value: true
  19. },
  20. list: {
  21. type: Array,
  22. value: [],
  23. observer: function (n, o) {
  24. if (!n || !n.length) return;
  25. if (this.chart) {
  26. const option = this.chart.getOption();
  27. option.series = n;
  28. this.chart.setOption(option);
  29. } else {
  30. this.setData({
  31. ec: {
  32. onInit: this.initChart.bind(this)
  33. }
  34. })
  35. }
  36. }
  37. },
  38. yType: {
  39. type: String,
  40. value: ""
  41. },
  42. xType: {
  43. type: String,
  44. value: ""
  45. }
  46. },
  47. chart: undefined,
  48. ready() {
  49. this.setData({
  50. ec: {
  51. onInit: this.initChart.bind(this)
  52. }
  53. })
  54. },
  55. // 销毁组件
  56. detached: function () {
  57. this.chart && this.chart.dispose && this.chart.dispose();
  58. },
  59. /**
  60. * 组件的初始数据
  61. */
  62. data: {
  63. ec: {
  64. onInit: undefined,
  65. lazyload: true
  66. },
  67. },
  68. /**
  69. * 组件的方法列表
  70. */
  71. methods: {
  72. initChart: function (canvas, width, height, dpr) {
  73. this.chart && this.chart.dispose && this.chart.dispose();
  74. this.chart = echarts.init(canvas, null, {
  75. width: width,
  76. height: height,
  77. devicePixelRatio: dpr // 像素
  78. });
  79. canvas.setChart(this.chart);
  80. // let colorList = ['9','a','b','c','d','e','f'], len = (this.data.list[0].data || []).length, colors = [];
  81. // for (let i = 0; i < len; i++) {
  82. // let color = "#";
  83. // for (let o = 0; o < 6; o++) {
  84. // color += colorList[Math.floor(Math.random()*7)]
  85. // }
  86. // colors.push(color);
  87. // }
  88. var option = {
  89. tooltip: {
  90. trigger: 'item',
  91. formatter: '{b}{d}%',
  92. position: [0, "90%"],
  93. textStyle: {
  94. color: "#fff"
  95. },
  96. },
  97. legend: {
  98. show: this.data.showLegend,
  99. left: 'left',
  100. itemGap: 1,
  101. itemWidth:4,
  102. itemHeight:4,
  103. textStyle: {
  104. color: "#fff"
  105. }
  106. },
  107. color: ["#dd79ff","#58d9f9"],
  108. // color: colors,
  109. series: this.data.list || []
  110. };
  111. this.chart.setOption(option);
  112. this.setData({
  113. show: true
  114. })
  115. return this.chart;
  116. },
  117. }
  118. })