pie_chart.vue 3.3 KB

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