ring_chart.vue 3.6 KB

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