ring_chart.vue 4.0 KB

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