peak_chart.vue 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193
  1. <template>
  2. <view class="charts-box">
  3. <qiun-data-charts canvas2d type="mount" :ontouch="true" :opts="opts" :chartData="chartData"
  4. :errorMessage="errorMessage" :errorReload="false" />
  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. isCanvas2d: process.uniEnv.isCanvas2d,
  18. chartData: {},
  19. errorMessage: '',
  20. //这里的 opts 是图表类型 type="mount" 的全部配置参数,您可以将此配置复制到 config-ucharts.js 文件中下标为 ['mount'] 的节点中来覆盖全局默认参数。实际应用过程中 opts 只需传入与全局默认参数中不一致的【某一个属性】即可实现同类型的图表显示不同的样式,达到页面简洁的需求。
  21. opts: {
  22. timing: "easeIn",
  23. duration: 1000,
  24. rotate: false,
  25. rotateLock: false,
  26. color: ["#1890FF", "#91CB74", "#FAC858", "#EE6666", "#73C0DE", "#3CA272", "#FC8452", "#9A60B4",
  27. "#ea7ccc"
  28. ],
  29. padding: [15, 15, 0, 5],
  30. fontSize: 15,
  31. fontColor: "#000000",
  32. dataLabel: true,
  33. dataPointShape: true,
  34. dataPointShapeType: "solid",
  35. touchMoveLimit: 60,
  36. enableScroll: true,
  37. enableMarkLine: false,
  38. legend: {
  39. show: false,
  40. position: "bottom",
  41. float: "center",
  42. padding: 5,
  43. margin: 5,
  44. backgroundColor: "rgba(0,0,0,0)",
  45. borderColor: "rgba(0,0,0,0)",
  46. borderWidth: 0,
  47. fontSize: 13,
  48. fontColor: "#666666",
  49. lineHeight: 11,
  50. hiddenColor: "#CECECE",
  51. itemGap: 10
  52. },
  53. xAxis: {
  54. disableGrid: true,
  55. disabled: false,
  56. axisLine: true,
  57. axisLineColor: "#CCCCCC",
  58. calibration: false,
  59. fontColor: "#717A89",
  60. fontSize: 12,
  61. lineHeight: 20,
  62. marginTop: 12,
  63. rotateLabel: true,
  64. rotateAngle: 45,
  65. itemCount: 5,
  66. boundaryGap: "center",
  67. splitNumber: 5,
  68. gridColor: "#CCCCCC",
  69. gridType: "solid",
  70. dashLength: 4,
  71. gridEval: 1,
  72. scrollShow: false,
  73. scrollAlign: "left",
  74. scrollColor: "#A6A6A6",
  75. scrollBackgroundColor: "#EFEBEF",
  76. title: "",
  77. titleFontSize: 13,
  78. titleOffsetY: 0,
  79. titleOffsetX: 0,
  80. titleFontColor: "#717A89",
  81. format: ""
  82. },
  83. yAxis: {
  84. data: [{
  85. min: 0
  86. }],
  87. disabled: true,
  88. disableGrid: false,
  89. splitNumber: 3,
  90. gridType: "dash",
  91. dashLength: 8,
  92. gridColor: "#CCCCCC",
  93. padding: 10,
  94. showTitle: false
  95. },
  96. extra: {
  97. mount: {
  98. type: "bar",
  99. widthRatio: 0.3,
  100. borderWidth: 1,
  101. barBorderCircle: false,
  102. barBorderRadius: [
  103. 12,
  104. 12,
  105. 0,
  106. 0
  107. ],
  108. linearType: "none",
  109. linearOpacity: 1,
  110. colorStop: 0
  111. },
  112. tooltip: {
  113. showBox: true,
  114. showArrow: true,
  115. showCategory: false,
  116. borderWidth: 0,
  117. borderRadius: 5,
  118. borderColor: "#000000",
  119. borderOpacity: 0.7,
  120. bgColor: "#000000",
  121. bgOpacity: 0.7,
  122. gridType: "dash",
  123. dashLength: 4,
  124. gridColor: "#cccccc",
  125. boxPadding: 3,
  126. fontSize: 13,
  127. lineHeight: 20,
  128. fontColor: "#FFFFFF",
  129. legendShow: true,
  130. legendShape: "diamond",
  131. splitLine: true,
  132. horizentalLine: true,
  133. xAxisLabel: false,
  134. yAxisLabel: false,
  135. labelBgColor: "#FFFFFF",
  136. labelBgOpacity: 0.7,
  137. labelFontColor: "#666666"
  138. },
  139. markLine: {
  140. type: "solid",
  141. dashLength: 4,
  142. data: []
  143. }
  144. }
  145. }
  146. };
  147. },
  148. onReady() {
  149. // this.getServerData();
  150. },
  151. methods: {
  152. getServerData() {
  153. //模拟从服务器获取数据时的延时
  154. setTimeout(() => {
  155. //模拟服务器返回数据,如果数据格式和标准格式不同,需自行按下面的格式拼接
  156. let res = {
  157. series: [{
  158. data: [{
  159. "name": "综合业务二部门",
  160. "value": 82
  161. }]
  162. }]
  163. };
  164. this.chartData = JSON.parse(JSON.stringify(res));
  165. }, 500);
  166. },
  167. setNoData() {
  168. this.chartData = {};
  169. this.errorMessage = '暂无数据'
  170. },
  171. setServerData(data) {
  172. setTimeout(() => {
  173. //模拟服务器返回数据,如果数据格式和标准格式不同,需自行按下面的格式拼接
  174. let res = {
  175. series: [{
  176. data: data
  177. }]
  178. };
  179. this.chartData = JSON.parse(JSON.stringify(res));
  180. }, 100);
  181. },
  182. }
  183. };
  184. </script>
  185. <style scoped>
  186. /* 请根据实际需求修改父元素尺寸,组件自动识别宽高 */
  187. .charts-box {
  188. width: 100%;
  189. height: 300px;
  190. }
  191. </style>