syampillai / SOCharts

A wrapper around the "echarts" JavaScript library to use it as a Vaadin component.
Apache License 2.0
27 stars 11 forks source link

Support the Sankey charts #14

Closed vilmosnagy closed 1 year ago

vilmosnagy commented 1 year ago

Hi,

I'd like to draw some Sankey charts with this lib. I tried to implement the chart to make a PR, but I've stuck at the following:

public class SankeyChart extends Chart {

    /**
     * Constructor.
     */
    public SankeyChart() {
        super(ChartType.Sankey);
    }

    @Override
    public void encodeJSON(StringBuilder sb) {
        super.encodeJSON(sb);
        sb.append("""
                ,
                  "layout": "none",
                  "emphasis": {
                    "focus": "adjacency"
                  },
                  "data": [
                    {
                      "name": "a"
                    },
                    {
                      "name": "b"
                    },
                    {
                      "name": "a1"
                    },
                    {
                      "name": "a2"
                    },
                    {
                      "name": "b1"
                    },
                    {
                      "name": "c"
                    }
                  ],
                  "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
                    }
                  ]
            """.stripIndent());
    }
}

The ChartType enum is extended with: Sankey(new String[] {}, false)

According to my understanding it should draw an example chart if I add the chart to a Vaadin layout, but instead of that nothing happens.

Could you help me a bit how to implement this PR?

Thanks, Vilmos

syampillai commented 1 year ago

You can have a look at the generated JSON (Override the customizeJSON(...) method and log it).

Also, Sankey chart is available in the latest version.

vilmosnagy commented 1 year ago

thanks <3

I tried to implement a custom chart type based on the echarts examples, but without success.