draw.tsx 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. import { defineComponent, ref, watch, shallowReactive } from 'vue'
  2. // 声明类型
  3. const PropsType = {
  4. cdata: {
  5. type: Object,
  6. require: true
  7. }
  8. } as const
  9. // 定义主体
  10. export default defineComponent({
  11. props: PropsType,
  12. setup(props) {
  13. // 定义 ref
  14. const chartRef = ref()
  15. // 配置项
  16. let options = shallowReactive({color:null,tooltip:null,toolbox:null,calculable:null,legend:null,series:null})
  17. watch(
  18. () => props.cdata,
  19. (val: any) => {
  20. options = {
  21. color: [
  22. '#37a2da',
  23. '#32c5e9',
  24. '#9fe6b8',
  25. '#ffdb5c',
  26. '#ff9f7f',
  27. '#fb7293',
  28. '#e7bcf3',
  29. '#8378ea'
  30. ],
  31. tooltip: {
  32. trigger: 'item',
  33. formatter: '{a} <br/>{b} : {c} ({d}%)'
  34. },
  35. toolbox: {
  36. show: true
  37. },
  38. calculable: true,
  39. legend: {
  40. orient: 'horizontal',
  41. icon: 'circle',
  42. bottom: 0,
  43. x: 'center',
  44. data: val.xData,
  45. textStyle: {
  46. color: '#fff'
  47. }
  48. },
  49. series: [
  50. {
  51. name: '通过率统计',
  52. type: 'pie',
  53. radius: [10, 50],
  54. roseType: 'area',
  55. center: ['50%', '40%'],
  56. itemStyle: {
  57. borderRadius: 5
  58. },
  59. label: {
  60. show: true,
  61. color: "#fff",
  62. },
  63. emphasis: {
  64. label: {
  65. show: false
  66. }
  67. },
  68. data: val.seriesData
  69. }
  70. ]
  71. }
  72. // 手动触发更新
  73. if (chartRef.value) {
  74. // 通过初始化参数打入数据
  75. chartRef.value.initChart(options)
  76. }
  77. },
  78. {
  79. immediate: true,
  80. deep: true
  81. }
  82. )
  83. return () => {
  84. const height = "220px"
  85. const width = "260px"
  86. return <div>
  87. <echart ref={chartRef} options={options} height={height} width={width} />
  88. </div>
  89. }
  90. }
  91. })