index.vue 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. <template>
  2. <div ref="disk" style="width: 130%; height: 100%;margin-left:-15%;margin-top:0%"></div>
  3. </template>
  4. <script>
  5. export default {
  6. props: {
  7. dataMap: { type: Object, default: () => [] },
  8. },
  9. data() {
  10. return {};
  11. },
  12. mounted() {
  13. this.getData();
  14. },
  15. watch: {
  16. dataMap(val) {
  17. this.getData(val);
  18. },
  19. },
  20. methods: {
  21. getData() {
  22. let that = this
  23. let dataMap = this.dataMap;
  24. let echartsMap = this.$echarts.getInstanceByDom(this.$refs.disk);
  25. if (echartsMap == null) {
  26. echartsMap = this.$echarts.init(this.$refs.disk);
  27. }
  28. echartsMap.setOption({
  29. // color:["#000","#fff"],
  30. tooltip: {
  31. formatter: function (info) {
  32. return [
  33. '<div class="tooltip-title">' +
  34. info.data.name +
  35. '</div>',
  36. '设备总数: ' + info.data.value + '</br>' +
  37. '在线数: ' + info.data.lineCount + '</br>' +
  38. '在线率: ' + info.data.lineRate + '%' + '</br>'
  39. ].join('');
  40. }
  41. },
  42. series: [
  43. {
  44. name: '物联网设备',
  45. type: 'treemap',
  46. visibleMin: 800,
  47. label: {
  48. show: true,
  49. formatter: '{b}'
  50. },
  51. itemStyle: {
  52. borderColor: '#fff'
  53. },
  54. levels: this.getLevelOption(),
  55. data: dataMap
  56. }
  57. ]
  58. });
  59. echartsMap.on('click', function (param) {
  60. that.$emit("echartsClick",param.data.deviceTypeCode)
  61. });
  62. },
  63. getLevelOption() {
  64. return [
  65. {
  66. itemStyle: {
  67. borderWidth: 0,
  68. gapWidth: 5
  69. }
  70. },
  71. {
  72. itemStyle: {
  73. gapWidth: 1
  74. }
  75. },
  76. {
  77. colorSaturation: [0.35, 0.5],
  78. itemStyle: {
  79. gapWidth: 1,
  80. borderColorSaturation: 0.6
  81. }
  82. }
  83. ];
  84. },
  85. resize() {
  86. // echarts.init(this.$refs.echartD).resize();
  87. },
  88. },
  89. };
  90. </script>
  91. <style scoped></style>