circle_chart.vue 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. <template>
  2. <view class="charts-box" :style="[{width},{height},]">
  3. <qiun-data-charts :canvas2d='isCanvas2d' :canvasId='canvasId' type="arcbar" :opts="opts"
  4. :chartData="chartData" />
  5. </view>
  6. </template>
  7. <script>
  8. export default {
  9. props: {
  10. width: {
  11. type: String,
  12. default: '140rpx'
  13. },
  14. height: {
  15. type: String,
  16. default: '140rpx'
  17. },
  18. canvasId: {
  19. type: String,
  20. default: ''
  21. },
  22. bgColor: {
  23. type: String,
  24. default: ()=>{
  25. return '#0FB160'
  26. }
  27. },
  28. },
  29. data() {
  30. return {
  31. isCanvas2d: process.uniEnv.isCanvas2d,
  32. chartData: {},
  33. //这里的 opts 是图表类型 type="arcbar" 的全部配置参数,您可以将此配置复制到 config-ucharts.js 文件中下标为 ['arcbar'] 的节点中来覆盖全局默认参数。实际应用过程中 opts 只需传入与全局默认参数中不一致的【某一个属性】即可实现同类型的图表显示不同的样式,达到页面简洁的需求。
  34. opts: {
  35. timing: "easeOut",
  36. duration: 1000,
  37. rotate: false,
  38. rotateLock: false,
  39. color: ["#1890FF", "#91CB74", "#FAC858", "#EE6666", "#73C0DE", "#3CA272", "#FC8452", "#9A60B4",
  40. "#ea7ccc"
  41. ],
  42. padding: undefined,
  43. fontSize: 13,
  44. fontColor: "#666666",
  45. dataLabel: true,
  46. dataPointShape: true,
  47. dataPointShapeType: "solid",
  48. touchMoveLimit: 60,
  49. enableScroll: false,
  50. enableMarkLine: false,
  51. title: {
  52. name: "",
  53. fontSize: 25,
  54. color: "#00FF00",
  55. offsetX: 0,
  56. offsetY: 0
  57. },
  58. subtitle: {
  59. name: "0%",
  60. fontSize: 15,
  61. color: "#666666",
  62. offsetX: 0,
  63. offsetY: 0
  64. },
  65. extra: {
  66. arcbar: {
  67. type: "circle",
  68. width: 10,
  69. backgroundColor: "#E9E9E9",
  70. startAngle: 0.5,
  71. endAngle: 0.25,
  72. gap: 2,
  73. direction: "cw",
  74. lineCap: "round",
  75. centerX: 0,
  76. centerY: 0,
  77. linearType: "none"
  78. }
  79. }
  80. }
  81. };
  82. },
  83. onReady() {
  84. // this.getServerData();
  85. },
  86. methods: {
  87. getServerData() {
  88. //模拟从服务器获取数据时的延时
  89. setTimeout(() => {
  90. //模拟服务器返回数据,如果数据格式和标准格式不同,需自行按下面的格式拼接
  91. let res = {
  92. series: [{
  93. name: "0%",
  94. // color: this.bgColor,
  95. data: 0
  96. }]
  97. };
  98. this.chartData = JSON.parse(JSON.stringify(res));
  99. }, 500);
  100. },
  101. setServerData(data) {
  102. console.log('series:' + data)
  103. this.opts.subtitle.name = (data * 100) + "%"
  104. setTimeout(() => {
  105. let res = {
  106. series: [{
  107. color: this.bgColor,
  108. data: data
  109. }]
  110. };
  111. this.chartData = JSON.parse(JSON.stringify(res));
  112. }, 100)
  113. }
  114. }
  115. };
  116. </script>
  117. <style scoped>
  118. </style>