echarts_round.vue 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. <template>
  2. <view class="">
  3. <view>
  4. <u-canvas ref="canvas" style="width: 80px; height: 100px;"></u-canvas>
  5. </view>
  6. </view>
  7. </template>
  8. <script>
  9. import * as echarts from 'echarts';
  10. export default{
  11. name:'echartsRound',
  12. data() {
  13. return{
  14. chartInstance: null,
  15. score: 45, // 假设评分为75%
  16. }
  17. },
  18. mounted() {
  19. this.initChart();
  20. },
  21. methods:{
  22. initChart() {
  23. const canvas = this.$refs.canvas;
  24. this.chartInstance = echarts.init(canvas);
  25. const option = {
  26. title: {
  27. text: `${this.score}分`,
  28. // subtext: '评分',
  29. left: 'center',
  30. top: 'center',
  31. textStyle: {
  32. fontSize: 12,
  33. fontWeight: 'bold',
  34. },
  35. subtextStyle: {
  36. fontSize: 16,
  37. color: '#999',
  38. }
  39. },
  40. series: [{
  41. name: 'Access From',
  42. type: 'pie',
  43. radius: ['40%', '70%'],
  44. avoidLabelOverlap: false,
  45. label: {
  46. show: false,
  47. position: 'center'
  48. },
  49. emphasis: {
  50. label: {
  51. show: true,
  52. fontSize: 40,
  53. fontWeight: 'bold'
  54. }
  55. },
  56. labelLine: {
  57. show: false
  58. },
  59. data: [{
  60. value: this.score,
  61. name: 'Search Engine'
  62. },
  63. {
  64. value: 100 - this.score,
  65. name: 'Direct'
  66. },
  67. ]
  68. }]
  69. };
  70. this.chartInstance.setOption(option);
  71. },
  72. }
  73. }
  74. </script>
  75. <style>
  76. </style>