pie3d.vue 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. <template>
  2. <div class="pie3d_con" :id="id"></div>
  3. </template>
  4. <script>
  5. import Highcharts from "highcharts/highstock";
  6. import Highcharts3D from "highcharts/highcharts-3d";
  7. Highcharts3D(Highcharts);
  8. export default({
  9. name: "pie3d",
  10. props:{
  11. id:{
  12. type:String,
  13. required:true
  14. },
  15. value1:{
  16. default:1,
  17. },
  18. value2:{
  19. default:1,
  20. },
  21. value3:{
  22. default:1,
  23. },
  24. },
  25. data() {
  26. return {
  27. }
  28. },
  29. mounted() {
  30. this.moreChart();
  31. },
  32. watch: {
  33. value1(){
  34. this.updataChart()
  35. },
  36. value2(){
  37. this.updataChart()
  38. },
  39. value3(){
  40. this.updataChart()
  41. },
  42. },
  43. methods: {
  44. updataChart(){
  45. const that = this
  46. this.chart.series[0].update({
  47. data:[
  48. ['全程温控',that.value1],
  49. ['实时温控',that.value2],
  50. ['追溯标签',that.value3],
  51. ]
  52. })
  53. },
  54. moreChart() {
  55. const that = this
  56. if (this.chart) {
  57. this.chart.destroy();
  58. }
  59. // 初始化 Highcharts 图表
  60. this.chart = new Highcharts.Chart(that.id, {
  61. chart: {
  62. type: 'pie',
  63. backgroundColor:"transparent",
  64. options3d: {
  65. enabled: true,
  66. alpha:50,
  67. beta: 0,
  68. },
  69. margin:[0,0,0,0],
  70. },
  71. credits:{enabled:false},
  72. colors:["#D8585C","#89D44B","#23D9E9"],
  73. title: false,
  74. tooltip: {
  75. pointFormat: '{name}: <b>{point.percentage:.1f}%</b>'
  76. },
  77. legend:false,
  78. plotOptions: {
  79. pie: {
  80. cursor: 'pointer',
  81. depth: 35,
  82. dataLabels: {
  83. // enabled: false,
  84. distance: -20,
  85. format: '{point.percentage:.1f}%',
  86. shadow:false,
  87. verticalAlign:"middle",
  88. },
  89. events:{
  90. hide:true
  91. },
  92. }
  93. },
  94. series: [{
  95. type: 'pie',
  96. center:["30%","40%"],
  97. data: [89
  98. ['全程温控',that.value1],
  99. ['实时温控',that.value2],
  100. ['追溯标签',that.value3],
  101. ]
  102. }]
  103. });
  104. }
  105. }
  106. })
  107. </script>
  108. <style>
  109. .pie3d_con{position: absolute; top: 0; left: 0; right: 0; bottom: 0; color: transparent;}
  110. .highcharts-text-outline{ display: none;}
  111. </style>