apache / echarts

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

[Feature] Parse SSR-generated chart from SVG to EchartsType on client #19109

Open putxe opened 12 months ago

putxe commented 12 months ago

What problem does this feature solve?

The sandbox here coming from the following page documentation shows that we have to re-render a chart on client side with its data to add some interactivity on it (like tooltip).

I would like to generate a chart on server-side (svg output), render it, and add some options on client-side (like tooltip for example) without creating a new graph.

What does the proposed API look like?

I suggest using a "parseSVG" or "parseSVGToEcharts" function which takes in input a stringified svg or inline svg and converts it to an EchartsType.

In that way, we could set options to this svg and render it on client :


const svgString = data.svgChart; // the generated svg chart coming from the server
const myChart = parseSvg(svgString) 

myChart.setOption({
    title: {
        text: 'YEAH'
    }
})
helgasoft commented 12 months ago

...we could set options to this svg and render it on client

Final myChart.setOption is client-rendering. Wouldn't that make SSR meaningless ? Server could just send partial XML option instead of SVG.

putxe commented 12 months ago

In fact I don't want to pass data series directly in the client. That's why generating a svg from the server and making it interactive on the client can be very useful for me.

helgasoft commented 12 months ago

I don't want to pass data series directly in the client.

Understandable if this is for security reasons, but data will still be exposed after parsing: const myChart = parseSvg(svgString); op = myChart.getOption(); console.log(op.series[0].data);

putxe commented 11 months ago

Yes you're right for sure. But a bit more complicated to scrape I think. Because I run a svelte kit application that shows all the data coming from the server in network tab, so I thought about sending only the generated chart from the server to the client instead of sending the data. And make the chart interactive then.

Ovilia commented 11 months ago

I don't understand how do you think it should provide the ability of tooltip if it were not rendered on the client side?

putxe commented 11 months ago

I want to render it on the client side (mandatory for displaying the tooltip). But instead of receiving options from the server (including data that can be accessed directly on the API endpoint), I would prefer to :

on server-side

on client-side

With this process, the data is a bit more complicated to access in my case (request my-endoint/__data.json will return an svg instead of options with data).

My main point with this issue is to add the ability to convert a svg to an echarts instance on the client side.