https://github.com/ecomfe/echarts-wordcloud
https://ecomfe.github.io/echarts-wordcloud/example/optionKeywords.html

echarts-cloud字符云 - 图1

https://ecomfe.github.io/echarts-wordcloud/example/wordCloud.html
echarts-cloud字符云 - 图2

  1. npm install echarts
  2. npm install echarts-wordcloud

vue使用

  1. <template>
  2. <div class="chart" ref="box"/>
  3. </template>
  4. <script>
  5. import * as echarts from 'echarts';
  6. import 'echarts-wordcloud';
  7. import {
  8. defineComponent, getCurrentInstance, onMounted,
  9. } from 'vue';
  10. const data = [
  11. {
  12. name: '春天的鸭子🦆',
  13. value: 100,
  14. },
  15. {
  16. name: 'Vue3 Admin',
  17. value: 50
  18. },
  19. {
  20. name: 'Hank',
  21. value: 25
  22. },
  23. {
  24. name: 'React技术',
  25. value: 150
  26. },
  27. {
  28. name: '数据可视化',
  29. value: 75
  30. },
  31. {
  32. name: '一条大鱼',
  33. value: 55
  34. }
  35. ];
  36. function getOptions() {
  37. return [
  38. {
  39. type: 'wordCloud',
  40. shape: 'circle', // 词云图形效果
  41. data,
  42. layoutAnimation: true,
  43. textStyle: {
  44. fontFamily: 'sans-serif',
  45. fontWeight: 'bold',
  46. // Color can be a callback function or a color string
  47. color() {
  48. const color = [
  49. Math.round(Math.random() * 160),
  50. Math.round(Math.random() * 160),
  51. Math.round(Math.random() * 160),
  52. ].join(',');
  53. return `rgb(${color})`;
  54. }
  55. },
  56. emphasis: {
  57. focus: 'self',
  58. textStyle: {
  59. shadowBlur: 10,
  60. shadowColor: '#333'
  61. },
  62. }
  63. }];
  64. }
  65. export default defineComponent({
  66. setup() {
  67. onMounted(() => {
  68. const { ctx } = getCurrentInstance();
  69. const element = ctx.$refs.box;
  70. console.log('ctx', element);
  71. // 基于准备好的dom,初始化echarts实例
  72. const myChart = echarts.init(element);
  73. // 绘制图表
  74. myChart.setOption({
  75. series: getOptions(),
  76. });
  77. });
  78. }
  79. });
  80. </script>
  81. <style scoped>
  82. .chart {
  83. height: 400px;
  84. }
  85. </style>

字符云原理

echarts-cloud字符云 - 图3