mixture_chart.vue 5.3 KB

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