3

What are some libraries for generating dynamic javascript charts that also provide fallback support to users without JS?

I'm looking at adding graphs to a website. I really like the way chart.js looks and acts. Chartjs would be great for most of my users that support JS, but I have a requirement to make the data also visible to my visitors with javascript disabled.

I don't want to display the data as a table to my noscript customers. I want the users without javascript to still see a graph that's capable of conveying all or most of the same data that would be visible in the more-interactive JS version of the graph.

My data only changes about once a day, so it would be ideal if I found a library that would just generate a static image of the graph and put that in a tag on the page where the JS graph would be.

Are there any libraries that can produce a nice JS graph for users with scripts enabled and a fallback png or jpg image for users with scripts disabled?

EDIT: fwiw, my server is running Debian Linux, and I'm open to using php, python, perl, bash (curl), or something similar in a cron job or something to automatically trigger the recommended library to export the graph to an image file.

2
  • How would it by possible if the script does not run? It should have some non-js functionality, or server-side functionality, too, to fill the content in <noscript> tags.
    – peterh
    Apr 6, 2020 at 10:10
  • You could fallback on something like image-charts.com for chart image generation :)
    – FGRibreau
    Apr 6, 2020 at 18:25

3 Answers 3

1

LightningChart JS has bitmap export with .saveToFile method, so it allows you to add the pic in IMG tag.

The chart also can be run in server-side with Node.js, and it allows you to write a solution to export images for non-JS-enabled clients.

0

You could use AmCharts, which has built-in support for exporting the JS-rendered charts to either a JPG or PNG since AMCharts4.

AmCharts is open-source using a custom license that just requires "prominent attribution" back to their project. Attribution can be removed with a commercial license.

As seen here, with some client-side javascript code plus some server-side python code, you could rig-up the chart to automatically be exported to an image file (javascript) and stored on the server (python) when the first javascript user visits your chart's page. This could be further automated by using a tool like uzbl-core or netserf or wkhtmltopdf or similar (all of these are CLI tools for loading a website in a virtual framebuffer with the command-line, and they all provide javascript support).

0

You could use plotly, which can easily export to a html/js file with write_html() and export to a PNG image with write_image()

I used this recently in an open-source project for generating graphs of COVID-19 data. At the time the site is generated, the data is parsed and output to both [a] an html file with the embedded JS for displaying the graph and [b] a PNG image of the graph.

Just under the <div> where the graph would be drawn with Javasript is a <noscript> tag that displays the PNG as a fallback for users without javascript.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.