sankey.vue 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. <template>
  2. <div id="sankey_echart" ref="echart"></div>
  3. </template>
  4. <script>
  5. // #5BB57A
  6. let option = {
  7. grid: {
  8. left: "20%",
  9. top: "20%",
  10. right: "40%",
  11. bottom: "20%",
  12. },
  13. tooltip: {
  14. trigger: "item",
  15. triggerOn: "mousemove",
  16. },
  17. // animation: false,
  18. series: {
  19. type: "sankey",
  20. layout: "none",
  21. left: "5%",
  22. bottom: "10%",
  23. // top: "50%",
  24. emphasis: {
  25. focus: "adjacency",
  26. },
  27. draggable: false, // 禁止拖动
  28. label: {
  29. position: "right",
  30. color: "#ECF6FF",
  31. formatter: function (params) {
  32. let name = params.name;
  33. return name.length > 5 ? name.substr(0, 5) + "..." : name;
  34. },
  35. },
  36. data: [],
  37. links: [],
  38. lineStyle: {
  39. color: "source",
  40. curveness: 0.5,
  41. },
  42. nodeWidth: 10,
  43. nodeAlign: "left",
  44. },
  45. };
  46. export default {
  47. name: "sankey_echart",
  48. components: {},
  49. data() {
  50. return {
  51. myChart: null,
  52. };
  53. },
  54. methods: {
  55. setOptions(data = [], links = []) {
  56. if (!this.myChart) {
  57. // var dom = document.getElementById("sankey_echart");
  58. this.myChart = echarts.init(this.$refs.echart);
  59. }
  60. option.series.data = data;
  61. option.series.links = links;
  62. this.myChart.setOption(option);
  63. },
  64. },
  65. mounted() {
  66. // this.setOptions();
  67. },
  68. };
  69. </script>
  70. <style lang="scss" scoped>
  71. .sankey_echart {
  72. width: 100%;
  73. height: 100%;
  74. }
  75. </style>