Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

While renderer as SVG the SaveAsImage png file can't use #7763

Open
KinkiWu opened this issue Feb 9, 2018 · 10 comments
Open

While renderer as SVG the SaveAsImage png file can't use #7763

KinkiWu opened this issue Feb 9, 2018 · 10 comments
Assignees
Milestone

Comments

@KinkiWu
Copy link

KinkiWu commented Feb 9, 2018

One-line summary [问题简述]

when we use renderer:'svg' to init the echart as following
echarts.init(element[0],theme,{renderer: 'svg'});
the SaveAsImage echart.png file can't use.

Version & Environment [版本及环境]

  • ECharts version [ECharts 版本]: 4.02
  • Browser version [浏览器类型和版本]: Chrome 63.0.3239.132
  • OS Version [操作系统类型和版本]: Win10

Expected behaviour [期望结果]

ECharts option [ECharts配置项]

option = {

}

Other comments [其他信息]

@KinkiWu KinkiWu changed the title while renderer as SVG the SaveAsImage png file can't use While renderer as SVG the SaveAsImage png file can't use Feb 9, 2018
@Ovilia
Copy link
Contributor

Ovilia commented Feb 11, 2018

Currently, only SVG file can be saved (with toolbox, set type to be svg) when rendering in SVG. We will improve it later to save as png.

@KinkiWu
Copy link
Author

KinkiWu commented Feb 12, 2018

@Ovilia Yes, now if I manually change the file extenstion from png to svg, the image file can open and view normally. @Ovilia Thanks for your help.

@vlakam
Copy link

vlakam commented Dec 7, 2018

When i set renderer to svg and use saveAsImage tool the resulting SVG goes like this
<svg xmlns="http://www.w3.org/2000/svg" version="1.1" baseProfile="full" style="position: absolute; left: 0px; top: 0px;" width="520" height="620"><path d="M 52 470.5 L 400 470.5" fill="none" stroke="

Which is totally invalid

@davidpham87
Copy link

Any update on this issue? :-)

@sswaroopk
Copy link

Have the same issue as commented by @vlakam , Got my exported svg as
<svg xmlns="http://www.w3.org/2000/svg" version="1.1" baseProfile="full" width="1366" height="562" style="user-select: none; position: absolute; left: 0px; top: 0px;"><path d="M 683 140.5 L 683 84.3 A 196.7 196.7 0 0 1 827.0271 147.0333 L 785.8765 185.3095 A 140.5 140.5 0 0 0 683 140.5 Z" fill="
Any updates?

@hughess
Copy link

hughess commented Nov 2, 2021

I'm also interested in saving images as png when using the svg renderer.

Is this on the roadmap?

@plainheart
Copy link
Member

@hughess Hi, it looks not very hard to implement and this feature could make the SVG renderer better. I'm going to take a try.

@plainheart plainheart self-assigned this Nov 3, 2021
@plainheart plainheart added this to the 5.3 milestone Nov 3, 2021
@plainheart plainheart modified the milestones: 5.3, 5.4 Jan 7, 2022
@hughess
Copy link

hughess commented May 9, 2022

@plainheart do you know what would need to be done to enable this? I might be able to take a look at it and contribute (depending on how difficult it is)

@plainheart
Copy link
Member

plainheart commented May 10, 2022

@hughess Glad to see you would like to help implement this feature! I'm sorry that I almost have forgotten it. We will mainly need to improve the echarts#getConnectedDataURL function to enable it. Now the SVG data URL can be generated synchronously, but when it comes to exporting other images of types in the SVG renderer, an asynchronous function may be needed. [1]

[1] To export the images of png/jpeg type, it should be necessary to create a temporary canvas to draw the SVG image and export it in other types via the canvas.toDataURL API when the SVG image is loaded and ready. This is also why it can't be in a synchronous way anymore.

@hughess
Copy link

hughess commented May 18, 2022

Thanks @plainheart. As a first step to understand how it would work, I did the following:

  • Used the svg renderer as normal to create and display a chart
  • Added a custom button outside of the ECharts instance - on click, the button runs a function which:
    • Generates the same chart, but using the canvas renderer
    • Puts the chart into a hidden div
    • Runs getConnectedDataURL with type = 'png'
    • Uses the download function from the npm package download.js to take the connectedDataURL and save it into a png file which is downloaded in the browser

This must be an inefficient way of doing it, but it works for our immediate use case. I plan to learn more about creating a temporary canvas from within ECharts so I can contribute back to the project.

@Ovilia Ovilia modified the milestones: 5.4, TBD Sep 1, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

7 participants