You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

105 lines
2.6KB

  1. import * as am4core from "@amcharts/amcharts4/core";
  2. import * as am4charts from "@amcharts/amcharts4/charts";
  3. import * as am4plugins_forceDirected from "@amcharts/amcharts4/plugins/forceDirected";
  4. // Create chart
  5. let chart = am4core.create("carto-bulles", am4plugins_forceDirected.ForceDirectedTree);
  6. // Create series
  7. let series = chart.series.push(new am4plugins_forceDirected.ForceDirectedSeries())
  8. series.dataSource.url = routes.app_carto_json;
  9. // Set data
  10. // series.data = [{
  11. // "name": "Nos révoltes",
  12. // "link": ["Nos rêves"],
  13. // "children": [{
  14. // "name": "A1", "value": 100
  15. // }, {
  16. // "name": "A2", "value": 60
  17. // }, {
  18. // "name": "A3", "value": 30
  19. // }]
  20. // }, {
  21. // "name": "Nos rêves",
  22. // "link": ["Les actions \n inspirantes"],
  23. // "children": [{
  24. // "name": "B1", "value": 135
  25. // }, {
  26. // "name": "B2", "value": 98
  27. // }, {
  28. // "name": "B3", "value": 56
  29. // }]
  30. // }, {
  31. // "name": "Les actions \n inspirantes",
  32. // "link": ["Les actions \n à booster"],
  33. // "children": [{
  34. // "name": "C1", "value": 335
  35. // }, {
  36. // "name": "C2", "value": 148
  37. // }, {
  38. // "name": "C3", "value": 126
  39. // }, {
  40. // "name": "C4", "value": 26
  41. // }]
  42. // }, {
  43. // "name": "Les actions \n à booster",
  44. // "link": ["Nos révoltes"],
  45. // "children": [{
  46. // "name": "D1", "value": 415
  47. // }, {
  48. // "name": "D2", "value": 148
  49. // }, {
  50. // "name": "D3", "value": 89
  51. // }, {
  52. // "name": "D4", "value": 64
  53. // }, {
  54. // "name": "D5", "value": 16
  55. // }]
  56. // }];
  57. series.nodes.template.events.on("hit", function(event) {
  58. console.log(event.target.dataItem.nb);
  59. });
  60. series.manyBodyStrength = -25;
  61. series.links.template.strength = 2;
  62. series.centerStrength = 1.2;
  63. //active le zoom
  64. chart.zoomable = true;
  65. //Nombre de level affiché par défaut
  66. series.maxLevels = 1
  67. //link entre "frere"
  68. // series.dataFields.id = "name";
  69. // series.dataFields.linkWith = "link";
  70. //distance entre les bulles
  71. series.links.template.distance = 1.7;
  72. // Set up data fields
  73. series.dataFields.name = "name";
  74. series.dataFields.children = "children";
  75. series.dataFields.nb = "nb";
  76. // Add labels
  77. series.nodes.template.label.text = "{name}";
  78. series.fontSize = 20;
  79. series.minRadius = 70;
  80. series.maxRadius = 100;
  81. //Couleur des bulles
  82. series.colors.list = [
  83. am4core.color("#dc5b2f"),
  84. am4core.color("#fce767"),
  85. am4core.color("#97533a"),
  86. am4core.color("#568b6f")
  87. ];
  88. //Apparence des liens entre les bulles
  89. series.links.template.strokeWidth = 5;
  90. series.links.template.strokeOpacity = 1;
  91. //tooltip
  92. series.nodes.template.tooltipText = "{nb}";