pie_chart.vue 3.4 KB

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