mixture_chart.vue 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270
  1. <template>
  2. <view class="charts-box">
  3. <qiun-data-charts type="mix" :opts="opts" :canvas2d='isCanvas2d' :canvasId='canvasId' :chartData="chartData" />
  4. </view>
  5. </template>
  6. <script>
  7. export default {
  8. props: {
  9. canvasId: {
  10. type: String,
  11. default: ''
  12. }
  13. },
  14. data() {
  15. return {
  16. chartData: {},
  17. //这里的 opts 是图表类型 type="mix" 的全部配置参数,您可以将此配置复制到 config-ucharts.js 文件中下标为 ['mix'] 的节点中来覆盖全局默认参数。实际应用过程中 opts 只需传入与全局默认参数中不一致的【某一个属性】即可实现同类型的图表显示不同的样式,达到页面简洁的需求。
  18. opts: {
  19. timing: "easeOut",
  20. duration: 1000,
  21. rotate: false,
  22. rotateLock: false,
  23. color: ["#EEF2FA"],
  24. padding: [15, 15, 0, 15],
  25. fontSize: 13,
  26. fontColor: "#666666",
  27. dataLabel: false,
  28. dataPointShape: false,
  29. dataPointShapeType: "solid",
  30. touchMoveLimit: 60,
  31. enableScroll: false,
  32. enableMarkLine: false,
  33. legend: {
  34. show: false,
  35. position: "bottom",
  36. float: "center",
  37. padding: 5,
  38. margin: 5,
  39. backgroundColor: "rgba(0,0,0,0)",
  40. borderColor: "rgba(0,0,0,0)",
  41. borderWidth: 0,
  42. fontSize: 13,
  43. fontColor: "#666666",
  44. lineHeight: 11,
  45. hiddenColor: "#CECECE",
  46. itemGap: 10
  47. },
  48. xAxis: {
  49. disableGrid: true,
  50. disabled: false,
  51. axisLine: false,
  52. axisLineColor: "#CCCCCC",
  53. calibration: false,
  54. fontColor: "#666666",
  55. fontSize: 13,
  56. lineHeight: 20,
  57. marginTop: 20,
  58. rotateLabel: false,
  59. rotateAngle: 45,
  60. itemCount: 5,
  61. boundaryGap: "center",
  62. splitNumber: 5,
  63. gridColor: "#CCCCCC",
  64. gridType: "solid",
  65. dashLength: 4,
  66. gridEval: 1,
  67. scrollShow: false,
  68. scrollAlign: "left",
  69. scrollColor: "#A6A6A6",
  70. scrollBackgroundColor: "#EFEBEF",
  71. title: "",
  72. titleFontSize: 13,
  73. titleOffsetY: 0,
  74. titleOffsetX: 0,
  75. titleFontColor: "#666666",
  76. format: ""
  77. },
  78. yAxis: {
  79. disabled: false,
  80. disableGrid: true,
  81. splitNumber: 4,
  82. gridType: "dash",
  83. dashLength: 4,
  84. gridColor: "#CCCCCC",
  85. padding: 10,
  86. showTitle: false,
  87. data: [{
  88. position: "left",
  89. title: "折线",
  90. calibration: false,
  91. type: "value",
  92. axisLineColor: "#ffffff"
  93. },
  94. {
  95. position: "right",
  96. min: 0,
  97. // max: 99999,
  98. title: "柱状图",
  99. textAlign: "left",
  100. disabled: false,
  101. axisLineColor: "#FFFFFF"
  102. },
  103. {
  104. position: "right",
  105. min: 0,
  106. // max: 99999,
  107. title: "点",
  108. textAlign: "left",
  109. calibration: false,
  110. disabled: true,
  111. axisLineColor: "#FFFFFF"
  112. }
  113. ]
  114. },
  115. extra: {
  116. mix: {
  117. column: {
  118. width: 30,
  119. seriesGap: 2,
  120. barBorderCircle: false,
  121. barBorderRadius: [
  122. 5,
  123. 5,
  124. 0,
  125. 0
  126. ],
  127. linearOpacity: 0.5,
  128. colorStop: 0
  129. },
  130. area: {
  131. opacity: 0.2,
  132. gradient: false
  133. },
  134. line: {
  135. width: 2
  136. }
  137. },
  138. tooltip: {
  139. showBox: true,
  140. showArrow: true,
  141. showCategory: false,
  142. borderWidth: 0,
  143. borderRadius: 0,
  144. borderColor: "#000000",
  145. borderOpacity: 0.7,
  146. bgColor: "#000000",
  147. bgOpacity: 0.7,
  148. gridType: "solid",
  149. dashLength: 4,
  150. gridColor: "#CCCCCC",
  151. boxPadding: 3,
  152. fontSize: 13,
  153. lineHeight: 20,
  154. fontColor: "#FFFFFF",
  155. legendShow: true,
  156. legendShape: "auto",
  157. splitLine: true,
  158. horizentalLine: false,
  159. xAxisLabel: false,
  160. yAxisLabel: false,
  161. labelBgColor: "#FFFFFF",
  162. labelBgOpacity: 0.7,
  163. labelFontColor: "#666666"
  164. },
  165. markLine: {
  166. type: "solid",
  167. dashLength: 4,
  168. data: []
  169. }
  170. }
  171. }
  172. };
  173. },
  174. onReady() {
  175. // this.getServerData();
  176. },
  177. methods: {
  178. getServerData() {
  179. //模拟从服务器获取数据时的延时
  180. setTimeout(() => {
  181. //模拟服务器返回数据,如果数据格式和标准格式不同,需自行按下面的格式拼接
  182. let res = {
  183. categories: ["2018", "2019", "2020", "2021", "2022"],
  184. series: [{
  185. name: "柱1",
  186. index: 1,
  187. type: "column",
  188. data: [160, {
  189. "value": 90,
  190. }, 100, 150, 90]
  191. },
  192. {
  193. name: "柱2",
  194. index: 1,
  195. type: "column",
  196. data: [160, {
  197. "value": 90,
  198. }, 100, 150, 90]
  199. },
  200. {
  201. name: "曲线",
  202. type: "line",
  203. style: "curve",
  204. color: "#FFD023",
  205. disableLegend: true,
  206. data: [70, 50, 85, 130, 64]
  207. },
  208. {
  209. name: "曲线",
  210. type: "line",
  211. style: "curve",
  212. color: "#0CAF60",
  213. disableLegend: true,
  214. data: [50, 20, 60, 100, 20]
  215. }
  216. ]
  217. };
  218. this.chartData = JSON.parse(JSON.stringify(res));
  219. }, 500);
  220. },
  221. setServerData(data){
  222. setTimeout(() => {
  223. //模拟服务器返回数据,如果数据格式和标准格式不同,需自行按下面的格式拼接
  224. let res = {
  225. categories: data.titles,
  226. series: [{
  227. name: "金额(男)",
  228. index: 1,
  229. type: "column",
  230. data: data.oneMoney
  231. },
  232. {
  233. name: "金额(女)",
  234. index: 2,
  235. type: "column",
  236. data: data.twoMoney
  237. },
  238. {
  239. name: "数量(男)",
  240. type: "line",
  241. style: "curve",
  242. color: "#FFD023",
  243. disableLegend: true,
  244. data: data.oneNum
  245. },
  246. {
  247. name: "数量(女)",
  248. type: "line",
  249. style: "curve",
  250. color: "#0CAF60",
  251. disableLegend: true,
  252. data: data.twoNum
  253. }
  254. ]
  255. };
  256. this.chartData = JSON.parse(JSON.stringify(res));
  257. }, 50);
  258. }
  259. }
  260. };
  261. </script>
  262. <style scoped>
  263. /* 请根据实际需求修改父元素尺寸,组件自动识别宽高 */
  264. .charts-box {
  265. width: 100%;
  266. height: 300px;
  267. }
  268. </style>