apache / echarts

Apache ECharts is a powerful, interactive charting and data visualization library for browser
https://echarts.apache.org
Apache License 2.0
60.19k stars 19.61k forks source link

[Feature] 桑基图是否支持legend? #20274

Open luhuiaaaluhui opened 1 month ago

luhuiaaaluhui commented 1 month ago

What problem does this feature solve?

目前在桑基图中增加legend的情况下是不起作用的

option = {
  series: {
    type: "sankey",
    layout: "none",
    emphasis: {
      focus: "adjacency",
    },
    legend: {
      data: ["1", "2", "3"],
      backgroundColor: "#ccc",
    },
    data: [
      {
        name: "a",
        category: "1",
      },
      {
        name: "b",
        category: "1",
      },
      {
        name: "a1",
        category: "2",
      },
      {
        name: "a2",
        category: "1",
      },
      {
        name: "b1",
        category: "3",
      },
      {
        name: "c",
        category: "1",
      },
    ],
    links: [
      {
        source: "a",
        target: "a1",
        value: 5,
      },
      {
        source: "a",
        target: "a2",
        value: 3,
      },
      {
        source: "b",
        target: "b1",
        value: 8,
      },
      {
        source: "a",
        target: "b1",
        value: 3,
      },
      {
        source: "b1",
        target: "a1",
        value: 1,
      },
      {
        source: "b1",
        target: "c",
        value: 2,
      },
    ],
    category: [{ name: "1" }, { name: "2" }, { name: "3" }],
  },
};

What does the proposed API look like?

想要让桑基图也可以支持标签过滤,显示关联关系,类似https://echarts.apache.org/examples/zh/editor.html?c=graph 中的图,可以根据标签筛选显示节点。

echarts-bot[bot] commented 1 month ago

@luhuiaaaluhui It seems you are not using English, I've helped translate the content automatically. To make your issue understood by more people and get helped, we'd like to suggest using English next time. 🤗

TRANSLATED
**BODY** ### What problem does this feature solve? Currently, adding legend to the Sankey diagram does not work. `option = { series: { type: "sankey", layout: "none", emphasis: { focus: "adjacency", }, legend: { data: ["1", "2", "3"], backgroundColor: "#ccc", }, data: [ { name: "a", category: "1", }, { name: "b", category: "1", }, { name: "a1", category: "2", }, { name: "a2", category: "1", }, { name: "b1", category: "3", }, { name: "c", category: "1", }, ], links: [ { source: "a", target: "a1", value: 5, }, { source: "a", target: "a2", value: 3, }, { source: "b", target: "b1", value: 8, }, { source: "a", target: "b1", value: 3, }, { source: "b1", target: "a1", value: 1, }, { source: "b1", target: "c", value: 2, }, ], category: [{ name: "1" }, { name: "2" }, { name: "3" }], }, };` ### What does the proposed API look like? I want the Sankey diagram to also support tag filtering and display relationships, similar to [https://echarts.apache.org/examples/zh/editor.html?c=graph](https://echarts.apache.org /examples/zh/editor.html?c=graph), you can filter and display nodes based on labels.
helgasoft commented 1 month ago

visualMap would have been the solution here, but looks like it does not work with sankey. Like:

  visualMap: {
    categories: ['1', '2', '3'],
    dimension: 'category'  // does not work with nodes data
  },

Another solution could be to use toggleSelect on edge category - Demo.

image