TaskCloud.vue 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. <template>
  2. <div id='taskWordCloud' style="height: 457px;width: 100%" ></div>
  3. </template>
  4. <script>
  5. import echarts from "echarts";
  6. // import resize from "./mixins/resize";
  7. import "echarts-wordcloud/dist/echarts-wordcloud";
  8. import "echarts-wordcloud/dist/echarts-wordcloud.min";
  9. export default {
  10. name: "TaskCloud",
  11. // mixins: [resize],
  12. props: ['info'],
  13. data() {
  14. return {
  15. chart: null
  16. };
  17. },
  18. mounted() {
  19. this.initChart();
  20. },
  21. beforeDestroy() {
  22. if (!this.chart) {
  23. return;
  24. }
  25. this.chart.dispose();
  26. this.chart = null;
  27. },
  28. methods: {
  29. initChart() {
  30. this.chart = echarts.init(document.getElementById('taskWordCloud'),{width:'auto',height:'500px'});
  31. const option = {
  32. backgroundColor: "#fff",
  33. // tooltip: {
  34. // pointFormat: "{series.name}: <b>{point.percentage:.1f}%</b>"
  35. // },
  36. series: [
  37. {
  38. type: "wordCloud",
  39. //用来调整词之间的距离
  40. gridSize: 10,
  41. //用来调整字的大小范围
  42. // Text size range which the value in data will be mapped to.
  43. // Default to have minimum 12px and maximum 60px size.
  44. sizeRange: [14, 60],
  45. // Text rotation range and step in degree. Text will be rotated randomly in range [-90, 90] by rotationStep 45
  46. //用来调整词的旋转方向,,[0,0]--代表着没有角度,也就是词为水平方向,需要设置角度参考注释内容
  47. // rotationRange: [-45, 0, 45, 90],
  48. // rotationRange: [ 0,90],
  49. rotationRange: [0, 0],
  50. //随机生成字体颜色
  51. // maskImage: maskImage,
  52. textStyle: {
  53. normal: {
  54. color: function() {
  55. return (
  56. "rgb(" +
  57. Math.round(Math.random() * 255) +
  58. ", " +
  59. Math.round(Math.random() * 255) +
  60. ", " +
  61. Math.round(Math.random() * 255) +
  62. ")"
  63. );
  64. }
  65. }
  66. },
  67. grid:{
  68. x:10,
  69. y:10,
  70. x2:10,
  71. y2:10,
  72. height:"500px",
  73. width:"100%"
  74. },
  75. //位置相关设置
  76. // Folllowing left/top/width/height/right/bottom are used for positioning the word cloud
  77. // Default to be put in the center and has 75% x 80% size.
  78. left: 0,
  79. top: 0,
  80. right: 0,
  81. bottom: 0,
  82. width: "100%",
  83. height: "100%",
  84. //数据
  85. data: this.info
  86. }
  87. ]
  88. };
  89. this.chart.setOption(option);
  90. }
  91. }
  92. }
  93. </script>
  94. <style lang='scss' scoped>
  95. .chartsClass {
  96. padding-left: 1.2rem;
  97. }
  98. #userWordCloud {
  99. box-shadow: 0 2px 12px 0 rgba(0, 0, 0, 0.1);
  100. }
  101. </style>