chart-progress.vue 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. <template>
  2. <view class="chart-progress">
  3. <canvas :canvas-id="chartID" :id="chartID" class="chart"></canvas>
  4. </view>
  5. </template>
  6. <script>
  7. import uCharts from './js/u-charts.js'
  8. export default {
  9. props: {
  10. chartID: {
  11. type: String,
  12. default: 'arcbar'
  13. },
  14. backgroundColor: {
  15. type: String,
  16. default: '#FFB769'
  17. },
  18. chartData: Object,
  19. width: String,
  20. height: String,
  21. title: {
  22. type: String,
  23. default() {
  24. return ''
  25. }
  26. },
  27. value: {
  28. type: String,
  29. default() {
  30. return ''
  31. }
  32. }
  33. },
  34. watch: {
  35. chartData: {
  36. handler() {
  37. this.draw(this.chartData)
  38. },
  39. immediate: true
  40. }
  41. },
  42. methods: {
  43. draw(data){
  44. new uCharts({
  45. $this: this,
  46. canvasId: this.chartID,
  47. type: 'arcbar',
  48. fontSize: 12,
  49. legend: { show: false },
  50. background: '#FFFFFF',
  51. pixelRatio: 1,
  52. series: data.series,
  53. animation: true,
  54. width: uni.upx2px(+this.width),
  55. height: uni.upx2px(+this.height),
  56. title: {
  57. name: this.title,
  58. color: '#333333',
  59. fontSize: uni.upx2px(26)
  60. },
  61. subtitle: {
  62. name: this.value,
  63. color: data.series[0].color,
  64. fontSize: uni.upx2px(24)
  65. },
  66. extra: {
  67. arcbar:{
  68. type:'circle', //整圆类型进度条图
  69. width: uni.upx2px(16), //圆弧的宽度
  70. startAngle: -0.5, //整圆类型只需配置起始角度即可
  71. backgroundColor: this.backgroundColor
  72. }
  73. }
  74. })
  75. }
  76. }
  77. }
  78. </script>
  79. <style lang="scss" scoped>
  80. .chart-progress, canvas {
  81. width: 100%;
  82. height: 100%;
  83. }
  84. </style>