chart-progress.vue 1.4 KB

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