ring_chart.vue 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  1. <template>
  2. <view class="charts-box" :style="[{width},{height},]">
  3. <qiun-data-charts type="ring" :opts="opts" :chartData="chartData" />
  4. </view>
  5. </template>
  6. <script>
  7. export default {
  8. props: {
  9. width: {
  10. type: String,
  11. default: '200rpx'
  12. },
  13. height: {
  14. type: String,
  15. default: '200rpx'
  16. },
  17. canvasId: {
  18. type: String,
  19. default: ''
  20. },
  21. bgChartColor: {
  22. type: Array,
  23. default: () => ["#00BF8A", "#2B7DFA"]
  24. },
  25. },
  26. data() {
  27. return {
  28. chartData: {},
  29. //这里的 opts 是图表类型 type="ring" 的全部配置参数,您可以将此配置复制到 config-ucharts.js 文件中下标为 ['ring'] 的节点中来覆盖全局默认参数。实际应用过程中 opts 只需传入与全局默认参数中不一致的【某一个属性】即可实现同类型的图表显示不同的样式,达到页面简洁的需求。
  30. opts: {
  31. timing: "easeOut",
  32. duration: 1000,
  33. rotate: false,
  34. rotateLock: false,
  35. color: ["#00BF8A", "#2B7DFA"],
  36. padding: [5, 5, 5, 5],
  37. fontSize: 13,
  38. fontColor: "#666666",
  39. dataLabel: false,
  40. dataPointShape: true,
  41. dataPointShapeType: "solid",
  42. touchMoveLimit: 60,
  43. enableScroll: false,
  44. enableMarkLine: false,
  45. legend: {
  46. show: false,
  47. position: "right",
  48. lineHeight: 25,
  49. float: "center",
  50. padding: 5,
  51. margin: 5,
  52. backgroundColor: "rgba(0,0,0,0)",
  53. borderColor: "rgba(0,0,0,0)",
  54. borderWidth: 0,
  55. fontSize: 13,
  56. fontColor: "#666666",
  57. hiddenColor: "#CECECE",
  58. itemGap: 10
  59. },
  60. title: {
  61. name: "",
  62. fontSize: 15,
  63. color: "#666666",
  64. offsetX: 0,
  65. offsetY: 0
  66. },
  67. subtitle: {
  68. name: "",
  69. fontSize: 20,
  70. color: "#7cb5ec",
  71. offsetX: 0,
  72. offsetY: 0
  73. },
  74. extra: {
  75. ring: {
  76. ringWidth: 12,
  77. activeOpacity: 0.5,
  78. activeRadius: 10,
  79. offsetAngle: 0,
  80. labelWidth: 15,
  81. border: true,
  82. borderWidth: 3,
  83. borderColor: "#FFFFFF",
  84. centerColor: "#FFFFFF",
  85. customRadius: 0,
  86. linearType: "none"
  87. },
  88. tooltip: {
  89. showBox: true,
  90. showArrow: true,
  91. showCategory: false,
  92. borderWidth: 0,
  93. borderRadius: 0,
  94. borderColor: "#000000",
  95. borderOpacity: 0.7,
  96. bgColor: "#000000",
  97. bgOpacity: 0.7,
  98. gridType: "solid",
  99. dashLength: 4,
  100. gridColor: "#CCCCCC",
  101. boxPadding: 3,
  102. fontSize: 13,
  103. lineHeight: 20,
  104. fontColor: "#FFFFFF",
  105. legendShow: true,
  106. legendShape: "auto",
  107. splitLine: true,
  108. horizentalLine: false,
  109. xAxisLabel: false,
  110. yAxisLabel: false,
  111. labelBgColor: "#FFFFFF",
  112. labelBgOpacity: 0.7,
  113. labelFontColor: "#666666"
  114. }
  115. }
  116. }
  117. };
  118. },
  119. created() {
  120. this.opts.color = this.bgChartColor
  121. },
  122. onReady() {
  123. this.getServerData();
  124. },
  125. methods: {
  126. getServerData() {
  127. //模拟从服务器获取数据时的延时
  128. setTimeout(() => {
  129. //模拟服务器返回数据,如果数据格式和标准格式不同,需自行按下面的格式拼接
  130. let res = {
  131. series: [{
  132. data: [{
  133. "name": "一班",
  134. "value": 50
  135. }, {
  136. "name": "二班",
  137. "value": 30
  138. }]
  139. }]
  140. };
  141. this.chartData = JSON.parse(JSON.stringify(res));
  142. }, 500);
  143. },
  144. }
  145. };
  146. </script>
  147. <style scoped>
  148. /* 请根据实际需求修改父元素尺寸,组件自动识别宽高 */
  149. .charts-box {
  150. width: 100%;
  151. height: 300px;
  152. }
  153. </style>