pie_chart.vue 3.4 KB

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