Echart.vue 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225
  1. <template>
  2. <view>
  3. <uni-ec-canvas
  4. class="uni-ec-canvas"
  5. id="line-chart"
  6. canvas-id="multi-charts-line"
  7. :ec="ec"
  8. ></uni-ec-canvas>
  9. <uni-ec-canvas
  10. class="uni-ec-canvas"
  11. id="pie-chart"
  12. canvas-id="multi-charts-pie"
  13. :ec="ec2"
  14. ></uni-ec-canvas>
  15. </view>
  16. </template>
  17. <script>
  18. import uniEcCanvas from "./UniEcCanvas.vue";
  19. export default {
  20. data() {
  21. return {
  22. ec: {
  23. option: {
  24. title: {
  25. text: ""
  26. },
  27. tooltip: {
  28. trigger: "axis",
  29. formatter: "{b}\r\n{c0}人",
  30. axisPointer: {
  31. type: "line",
  32. axis: "x",
  33. label: {
  34. backgroundColor: "#000000"
  35. }
  36. }
  37. },
  38. grid: {
  39. left: "6%",
  40. right: "6%",
  41. top: "6%",
  42. bottom: "6%",
  43. containLabel: true
  44. },
  45. xAxis: {
  46. type: "category",
  47. boundaryGap: false,
  48. data: ["2-12", "2-14", "2-16", "2-18", "2-20", "2-22", "2-24"],
  49. axisLine: {
  50. // y轴
  51. show: false
  52. },
  53. axisTick: {
  54. // y轴刻度线
  55. show: false
  56. },
  57. splitLine: {
  58. // 网格线
  59. show: false
  60. }
  61. },
  62. yAxis: {
  63. type: "value",
  64. axisLine: {
  65. // y轴
  66. show: false
  67. },
  68. axisTick: {
  69. // y轴刻度线
  70. show: false
  71. },
  72. splitLine: {
  73. // 网格线
  74. show: false
  75. }
  76. },
  77. series: [
  78. {
  79. name: "浏览量",
  80. type: "line",
  81. smooth: true,
  82. areaStyle: {
  83. color: {
  84. type: "linear",
  85. x: 0,
  86. y: 0,
  87. x2: 0,
  88. y2: 1,
  89. colorStops: [
  90. {
  91. offset: 0,
  92. color: "#E50113" // 0% 处的颜色
  93. },
  94. {
  95. offset: 1,
  96. color: "#fff" // 100% 处的颜色
  97. }
  98. ],
  99. global: false // 缺省为 false
  100. }
  101. },
  102. lineStyle: {
  103. color: "#EF5959"
  104. },
  105. data: [120, 132, 101, 134, 90, 230, 210]
  106. }
  107. ]
  108. }
  109. },
  110. ec2: {
  111. option: {
  112. title: {
  113. text: "7,5950",
  114. left: "center",
  115. top: "40%",
  116. subtext: "客户总数",
  117. subtextStyle: {
  118. color: "#959595",
  119. fontSize: 12,
  120. align: "center"
  121. },
  122. textStyle: {
  123. color: "#19193E",
  124. fontSize: 23,
  125. align: "center"
  126. }
  127. },
  128. series: [
  129. {
  130. name: "访问来源",
  131. type: "pie",
  132. radius: ["40%", "60%"],
  133. label: {
  134. position: "outside",
  135. color: "#19193E",
  136. normal: {
  137. show: false
  138. },
  139. emphasis: {
  140. show: true
  141. },
  142. fontSize: 10
  143. },
  144. labelLine: {
  145. normal: {
  146. show: false
  147. },
  148. emphasis: {
  149. show: true
  150. }
  151. },
  152. data: [
  153. {
  154. value: 3321,
  155. name: "直销中心",
  156. itemStyle: {
  157. normal: { color: "#EF5959" },
  158. emphasis: { color: "#EF5959" }
  159. }
  160. },
  161. {
  162. value: 1148,
  163. name: "手动录入",
  164. itemStyle: {
  165. normal: { color: "#ffa974" },
  166. emphasis: { color: "#ffa974" }
  167. }
  168. },
  169. {
  170. value: 2532,
  171. name: "线上访客",
  172. itemStyle: {
  173. normal: { color: "#ffc68a" },
  174. emphasis: { color: "#ffc68a" }
  175. }
  176. },
  177. {
  178. value: 1148,
  179. name: "线下拓客",
  180. itemStyle: { color: "#F0DD93" }
  181. },
  182. {
  183. value: 1148,
  184. name: "名片海报",
  185. itemStyle: { color: "#E7CB84" }
  186. },
  187. {
  188. value: 1148,
  189. name: "自然来访",
  190. itemStyle: { color: "#7EBD95" }
  191. },
  192. { value: 1148, name: "分享家", itemStyle: { color: "#687793" } }
  193. ]
  194. }
  195. ]
  196. }
  197. }
  198. };
  199. },
  200. onReady() {
  201. setTimeout(() => {
  202. this.ec.option.series[0].data = [1, 2, 3, 4, 5, 6, 7];
  203. console.log("折线图数据改变啦");
  204. }, 1000);
  205. setTimeout(() => {
  206. //数组内的数据要$set哦
  207. this.ec2.option.series[0].data[0].value = 0;
  208. console.log("折线图数据改变啦");
  209. }, 2000);
  210. },
  211. components: {
  212. uniEcCanvas
  213. }
  214. };
  215. </script>
  216. <style scoped>
  217. .uni-ec-canvas {
  218. width: 750upx;
  219. height: 750upx;
  220. display: block;
  221. }
  222. </style>