amcharts / amcharts3

JavaScript Charts V3
Other
395 stars 129 forks source link

amCharts supported for SVG Server Side Render? #102

Open austinrh322 opened 7 years ago

austinrh322 commented 7 years ago

Hello,

I'm trying to generate the SVG charts from amCharts through NodeJs and JSDOM. I'm outputting everything right on the server, but cannot generate the graphs. I would like to know before I spend anymore time, is amCharts even compatible with server side chart generation?

Thanks!

martynasma commented 7 years ago

I'm afraid we don't have any specific support for server-side chart generation.

That being said it might still be possible depending on what your end-goal is.

If you just want to take a snapshot of a rendered chart, you might want to look into PhantomJS:

https://www.amcharts.com/kbase/automate-report-generation-using-phantomjs/

austinrh322 commented 7 years ago

Thanks for the response. We're interested in just fetching the SVG after passing the chart the necessary values. We'd like then to convert the SVG to Base64 for storage.

I have this already working in Phantom, but thought we could eliminate the need for the browser portion completely.

Thanks!

On February 23, 2017 at 12:16:23 AM, Martynas Majeris ( notifications@github.com) wrote:

I'm afraid we don't have any specific support for server-side chart generation.

That being said it might still be possible depending on what your end-goal is.

If you just want to take a snapshot of a rendered chart, you might want to look into PhantomJS:

https://www.amcharts.com/kbase/automate-report-generation-using-phantomjs/

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/amcharts/amcharts3/issues/102#issuecomment-281897090, or mute the thread https://github.com/notifications/unsubscribe-auth/AYwzZGmDHqJ8N2RANjCRBP9iYLoKnnR9ks5rfRYngaJpZM4MJLFi .

martynasma commented 7 years ago

Well, I'm not entirely sure it will be possible with NodeJS alone. amCharts relies on DOM being there - both structure and events. I suppose that's where JSDOM comes in.

I don't have enough experience with both of the above to tell for sure, but technically it might be possible to run an amCharts code in your NodeJS script along JSDOM. Catch rendered event and utilize Export plugin's API to export SVG snapshot of the chart, then save it on server.

Here's an example on how to grab Base64 snapshot of the chart via API: https://www.amcharts.com/kbase/get-base64-representation-chart-image/

I'm sorry, but I don't have any similar examples to the rest of the solution.

I hope this helps.

EmirGluhbegovic commented 7 years ago

@austinrh322 Hey, I have come across the same issue and am wondering if you have found a solution? Did you manage to use jsDom with amcharts?

austinrh322 commented 7 years ago

The only way to do it, and is supported by amCharts, is to use PhantomJS. I created an HTML template with the graphs, and using a .Net wrapper was able to invoke Phantom to render the pdf as a byte array for db storage. Only way I'm afraid.

On Mar 30, 2017, 4:16 AM -0400, Eglu notifications@github.com, wrote:

@austinrh322 (https://github.com/austinrh322) Hey, I have come across the same issue and am wondering if you have found a solution?

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub (https://github.com/amcharts/amcharts3/issues/102#issuecomment-290336547), or mute the thread (https://github.com/notifications/unsubscribe-auth/AYwzZBq9YzH4EngxLBbUtkhpwya9tH-Tks5rq2TRgaJpZM4MJLFi).

EmirGluhbegovic commented 7 years ago

@austinrh322 I need to have automated reports running in the background. Do you create a html page just for rendering the amcharts then have phantom run that page and save the images to a specified file, then fetch those images and insert into the PDF?

austinrh322 commented 7 years ago

@eglu, you can use Phantom for direct pdf generation with the charts. It basically screen scrapes the html, including the charts. If you are just interested in the charts as images themselves, investigate using PDFMake which is supported by amCharts to output the individual charts as PNG/JPG.

On Mon, Apr 10, 2017 at 7:26 AM Eglu notifications@github.com wrote:

@austinrh322 https://github.com/austinrh322 I need to have automated reports running in the background. Do you create a html page just for rendering the amcharts then have phantom run that page and save the images to a specified file, then fetch those images and insert into the PDF?

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/amcharts/amcharts3/issues/102#issuecomment-292922592, or mute the thread https://github.com/notifications/unsubscribe-auth/AYwzZFRNy-ULjnNOIYKKSwcDcNvhNVU0ks5ruhH4gaJpZM4MJLFi .