效果

散点图.png

代码

  1. const data = [{
  2. "catalogName": "测试一",
  3. "total": 17,
  4. "ratio": 34.00
  5. }, {
  6. "catalogName": "测试一测试",
  7. "total": 16,
  8. "ratio": 32.00
  9. }, {
  10. "catalogName": "测试二",
  11. "total": 8,
  12. "ratio": 16.00
  13. }, {
  14. "catalogName": "测试三",
  15. "total": 4,
  16. "ratio": 8.00
  17. }, {
  18. "catalogName": "测试四",
  19. "total": 3,
  20. "ratio": 6.00
  21. }, {
  22. "catalogName": "测试无",
  23. "total": 2,
  24. "ratio": 4.00
  25. }]
  26. const colors = ['#4983F5', '#3D993D', '#525CCC', '#3344FF', '#39ACE5', '#008099', '#2985CC']
  27. const seriesData = data.map((item, index) => {
  28. return {
  29. "name": item.catalogName,
  30. "value": item.total,
  31. "ratio": item.ratio,
  32. "symbolSize": item.ratio * 2 + 60,
  33. "draggable": true,
  34. itemStyle: {
  35. normal: {
  36. color: {
  37. type: 'linear',
  38. colorStops: [{
  39. offset: 0,
  40. color: colors[index % colors.length],
  41. }, ],
  42. global: true,
  43. },
  44. },
  45. },
  46. }
  47. });
  48. const option = {
  49. tooltip: {
  50. formatter: (params) => `${params.marker}${params.data.name}:${params.data.value} ${params.data.ratio}%`,
  51. },
  52. series: [{
  53. type: 'graph',
  54. layout: 'force',
  55. force: {
  56. repulsion: [80, 240],
  57. },
  58. roam: true,
  59. label: {
  60. normal: {
  61. show: true,
  62. color: '#FFFFFF',
  63. fontWeight: 'bolder',
  64. }
  65. },
  66. data: seriesData
  67. }]
  68. }