index.js 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224
  1. import * as echarts from '../ec-canvas/echarts'
  2. import { mergeOptions } from '../ec-canvas/defaultOption'
  3. Component({
  4. /**
  5. * 组件的属性列表
  6. */
  7. properties: {
  8. },
  9. /**
  10. * 组件的初始数据
  11. */
  12. data: {
  13. ec: {
  14. onInit: initChart
  15. },
  16. barEc: {
  17. onInit: initBarChart
  18. },
  19. pieEc : {
  20. onInit: initSexPieChart
  21. },
  22. areaPieEc: {
  23. onInit: initAreaPieChart
  24. }
  25. },
  26. /**
  27. * 组件的方法列表
  28. */
  29. methods: {
  30. }
  31. })
  32. function initChart(canvas, width, height, dpr) {
  33. const chart = echarts.init(canvas, null, {
  34. width: width,
  35. height: height,
  36. devicePixelRatio: dpr // new
  37. });
  38. canvas.setChart(chart);
  39. var option = {
  40. title: {
  41. text: '新老客户统计'
  42. },
  43. series: [
  44. {
  45. data: [[0, 1000], [3, 500], [6, 750], [9, 1400], [12, 1250], [15, 1600], [18, 1800]],
  46. type: 'line',
  47. smooth: true,
  48. name: '新客户',
  49. areaStyle: {
  50. opacity: 0.1
  51. },
  52. symbolSize: 0
  53. },
  54. {
  55. data: [[0, 1250], [3, 600], [6, 800], [9, 1500], [12, 1400], [15, 1750], [18, 2000]],
  56. type: 'line',
  57. smooth: true,
  58. name: '老客户',
  59. areaStyle: {
  60. opacity: 0.1
  61. },
  62. symbolSize: 0
  63. },
  64. ]
  65. };
  66. chart.setOption(mergeOptions(option));
  67. return chart;
  68. }
  69. function initBarChart(canvas, width, height, dpr) {
  70. const chart = echarts.init(canvas, null, {
  71. width: width,
  72. height: height,
  73. devicePixelRatio: dpr // new
  74. });
  75. canvas.setChart(chart);
  76. var option = {
  77. title: {
  78. text: '客户来源统计'
  79. },
  80. xAxis: {
  81. type: 'value',
  82. axisLabel: {
  83. align: 'center'
  84. }
  85. },
  86. yAxis: {
  87. type: 'category',
  88. data: ['网页', 'APP', '小程序', '其它'],
  89. axisLabel: {
  90. margin: 0
  91. }
  92. },
  93. series: [
  94. {
  95. type: 'bar',
  96. data: [{
  97. value: 2,
  98. itemStyle: {
  99. }
  100. }, 4.9, 7.0, 11],
  101. barGap: 0,
  102. barWidth: 10,
  103. itemStyle: {
  104. barBorderRadius:[0, 10, 10, 0],
  105. }
  106. }
  107. ]
  108. };
  109. chart.setOption(mergeOptions(option));
  110. return chart;
  111. }
  112. function initSexPieChart(canvas, width, height, dpr) {
  113. const chart = echarts.init(canvas, null, {
  114. width: width,
  115. height: height,
  116. devicePixelRatio: dpr // new
  117. });
  118. canvas.setChart(chart);
  119. var option = {
  120. title: {
  121. text: '客户性别统计'
  122. },
  123. xAxis: {
  124. show: false
  125. },
  126. yAxis: {
  127. show: false
  128. },
  129. color: ['#17D2D2','#FAD43B','#4DAEFF','#F69758','#738EFE','#c23531','#2f4554', '#61a0a8', '#d48265', '#91c7ae','#749f83', '#ca8622', '#bda29a','#6e7074', '#546570', '#c4ccd3'],
  130. legend: {
  131. left: 'center',
  132. bottom: 0,
  133. top: null,
  134. data: ['男性:50%', '女性:50%', '1性:50%']
  135. },
  136. series: [
  137. {
  138. data: [[0, 1000], [3, 500], [6, 750], [9, 1400], [12, 1250], [15, 1600], [18, 1800]],
  139. type: 'pie',
  140. radius: ['30%', '50%'],
  141. data: [
  142. { value: 100, name: '男性:50%' },
  143. { value: 100, name: '女性:50%' },
  144. { value: 100, name: '1性:50%' },
  145. ],
  146. label: {
  147. show: false,
  148. position: 'center'
  149. },
  150. labelLine: {
  151. show: false
  152. }
  153. }
  154. ]
  155. };
  156. chart.setOption(mergeOptions(option));
  157. return chart;
  158. }
  159. function initAreaPieChart(canvas, width, height, dpr) {
  160. const chart = echarts.init(canvas, null, {
  161. width: width,
  162. height: height,
  163. devicePixelRatio: dpr // new
  164. });
  165. canvas.setChart(chart);
  166. var option = {
  167. title: {
  168. text: '客户区域统计'
  169. },
  170. xAxis: {
  171. show: false
  172. },
  173. yAxis: {
  174. show: false
  175. },
  176. color: ['#17D2D2','#FAD43B','#4DAEFF','#F69758','#738EFE','#c23531','#2f4554', '#61a0a8', '#d48265', '#91c7ae','#749f83', '#ca8622', '#bda29a','#6e7074', '#546570', '#c4ccd3'],
  177. legend: {
  178. left: 'center',
  179. bottom: 0,
  180. top: null,
  181. data: ['男性:50%', '女性:50%', '1性:50%']
  182. },
  183. series: [
  184. {
  185. data: [[0, 1000], [3, 500], [6, 750], [9, 1400], [12, 1250], [15, 1600], [18, 1800]],
  186. type: 'pie',
  187. radius: ['30%', '50%'],
  188. data: [
  189. { value: 100, name: '男性:50%' },
  190. { value: 100, name: '女性:50%' },
  191. { value: 100, name: '1性:50%' },
  192. ],
  193. label: {
  194. show: false,
  195. position: 'center'
  196. },
  197. labelLine: {
  198. show: false
  199. }
  200. }
  201. ]
  202. };
  203. chart.setOption(mergeOptions(option));
  204. return chart;
  205. }