index1.vue 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. <template>
  2. <el-row>
  3. <div id="index1" style="width:100%;height:100%;"></div>
  4. </el-row>
  5. </template>
  6. <script>
  7. import * as echarts from "echarts";
  8. export default {
  9. props: ["resData"],
  10. data() {
  11. return {};
  12. },
  13. watch: {
  14. resData() {
  15. this.getData();
  16. }
  17. },
  18. methods: {
  19. getData() {
  20. let chartDom = document.getElementById("index1");
  21. let myChart = echarts.init(chartDom);
  22. let data = this.resData.map(val => {
  23. return {
  24. name: val.deviceTypeS,
  25. value: val.deviceCount
  26. };
  27. });
  28. let total = 0;
  29. data.forEach(val => {
  30. total += val.value;
  31. });
  32. let option = {
  33. title: [
  34. {
  35. text: "{name|" + total + "}\n{val|设备总数}",
  36. top: "center",
  37. left: "center",
  38. textStyle: {
  39. rich: {
  40. name: {
  41. fontSize: 25,
  42. fontWeight: "normal",
  43. color: "#37FF01"
  44. },
  45. val: {
  46. fontSize: 14,
  47. fontWeight: "bold",
  48. color: "#02DDF2"
  49. }
  50. }
  51. }
  52. }
  53. ],
  54. tooltip: {
  55. trigger: "item",
  56. formatter: function(params) {
  57. return (
  58. params.name +
  59. ":" +
  60. params.value +
  61. "<br>占比:" +
  62. params.percent.toFixed(2) +
  63. "%"
  64. );
  65. }
  66. },
  67. series: [
  68. {
  69. label: {
  70. normal: {
  71. show: true,
  72. formatter: " {b}:{c} "
  73. },
  74. emphasis: {
  75. show: true
  76. }
  77. },
  78. name: "访问来源",
  79. radius: ["45%", "60%"],
  80. type: "pie", // 设置图表类型为饼图
  81. // data: []
  82. data: data
  83. }
  84. ],
  85. color: ['#FF0087', '#00DDFF', '#37A2FF', '#FF5801', '#FFBF00']
  86. };
  87. option && myChart.setOption(option);
  88. window.addEventListener("resize", function() {
  89. myChart.resize();
  90. });
  91. },
  92. }
  93. };
  94. </script>
  95. <style lang="scss" scoped></style>