chart1.vue 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. <template>
  2. <div class="w-100% h-100%" id="myChart3"></div>
  3. </template>
  4. <script setup lang="ts">
  5. import { onMounted, ref } from 'vue'
  6. import * as echarts from 'echarts'
  7. const initChart = () => {
  8. let myChart = echarts.init(document.getElementById('myChart3'))
  9. var symbolSizeArr = [60, 78, 65, 98]
  10. let option = {
  11. tooltip: {
  12. show: false
  13. },
  14. xAxis: {
  15. show: false
  16. },
  17. yAxis: {
  18. show: false
  19. },
  20. series: [
  21. {
  22. type: 'graph',
  23. layout: 'force',
  24. force: {
  25. repulsion: 200,
  26. edgeLength: 10
  27. },
  28. label: {
  29. show: true,
  30. textStyle: {
  31. color: '#fff', // 标签字体颜色
  32. fontSize: 14, // 标签字体大小
  33. fontFamily: 'AlibabaPuHuiTiR' // 标签字体
  34. },
  35. // formatter: ['{title|{c}人}', '{name|{b}}'].join('\n'),
  36. formatter: function (value) {
  37. if (value.name.length > 2) {
  38. return (
  39. value.name.substring(0, 2) +
  40. '\n' +
  41. value.name.substring(2, value.name.length) +
  42. '\n' +
  43. value.value +
  44. '人'
  45. )
  46. } else {
  47. return value.name + '\n' + value.value + '人'
  48. }
  49. }
  50. },
  51. itemStyle: {
  52. color: function (params) {
  53. var colorList = [
  54. 'rgba(9,217,205,0.5)',
  55. 'rgba(28,162,255,0.5)',
  56. 'rgba(228,163,6,0.5)',
  57. 'rgba(238,102,102,0.5)'
  58. ]
  59. var color = new echarts.graphic.LinearGradient(0, 0, 0, 1, [
  60. {
  61. offset: 0,
  62. color: colorList[params.dataIndex % 6]
  63. },
  64. {
  65. offset: 1,
  66. color: colorList[params.dataIndex % 6]
  67. }
  68. ])
  69. return color //大概最新的柱子颜色始终一样的 不太理解
  70. }
  71. },
  72. symbolSize: function (value, params) {
  73. return symbolSizeArr[params.dataIndex]
  74. },
  75. draggable: true, //设置是否可拖动
  76. data: [
  77. {
  78. name: '系统分析师',
  79. value: 1
  80. },
  81. {
  82. name: '项目管理师',
  83. value: 3
  84. },
  85. {
  86. name: '系统架构师',
  87. value: 2
  88. },
  89. {
  90. name: '其他',
  91. value: 8
  92. }
  93. ]
  94. }
  95. ]
  96. }
  97. myChart.setOption(option)
  98. }
  99. /** 初始化 **/
  100. onMounted(() => {
  101. initChart()
  102. })
  103. </script>
  104. <style lang="scss" scoped></style>