They seem to be using Rollup for builds, which supports ESM output, so they wouldn't even need to do any refactoring for that. Couple of configuration changes would suffice.
> is all this trickery on top of a library like this one still needed?
If the library is imported in the way that the article recommends in step two, it's not actually loaded as an ES6 module. This code checks to see if we're currently acting as a module and accordingly makes sure that the library is available as a global object. See this link for some examples: https://devhints.io/umdjs
> I have no idea how to read this ...
I tried to add some comments [0] which will hopefully help!
UMD does _not_ support standard JS module imports. The UMD code won't detect `exports` or `define` and will write to globals instead of producing any exports.
The GP wants to import into JS modules, and you said:
> Yes, this is the point of that code. It's boilerplate to ensure the module loads in different environments.
but the UDM header does not allow the module to load in JS modules. So I'm not quite sure what you meant actually. The header does nothing for standard modules.
I love chartjs. It's so easy to get started with it and comes with a lot of great features out of the box. I just wish its animation system was a little more extensive like giving me the option to animate ticks and grid lines for eye candy on load.
I like Chart.js as well. I found it very easy to pick up as an ad-hoc Javascript programmer, producing some nice visual depictions of the data coming out of my C/C++ code.
Interesting. Do you know how Apexcharts.js performs with real-time graphs? We're currently using Chart.js via react-chartjs-2 and while it works, it's consuming quite a bit of CPU.
There have been two major changes in Chart.js that will dramatically improve performance in the upcoming 2.9.0 release. We're also adding a section to the documentation about options you can set to improve performance over the defaults. We're hoping to release soon, but there are a couple pending PRs we'd like to review first
I think most chart libraries use SVG. There are trade-offs between the two approaches and both have their advantages. One of the places that canvas really shines is performance. In the past I've found Chart.js and some of the faster SVG libraries to be about on par with each other, but the upcoming Chart.js 2.9.0 release has had a couple major performance improvements that I think will make it significantly faster than probably any SVG library. It's an area we'll continue to work on since it's one of the main reasons to choose a canvas implementation over an SVG implementation.
I think the other advantage SVG has can be is if you want to do some advanced interactivity. That can sometimes be easier in SVG.
i'm working on a micro timeseries plotter that easily handles 150k+ datapoints. it uses canvas but accounts properly for display pixel density, so is as sharp as SVG.
If you change the `scales.xAxes[0].ticks.source config option to `'auto'` you can drop ~1s off the render the time. It's still not great, but it is an improvement. I'll take a look through the profile I generated and see if there are any obvious improvements in Chart.js.
I work on a data viz product and we've always struggled with a myriad of charting libraries. IMO Chart.js is one of the best tools for charting that has quickly surpassed existing libraries in aesthetics, ease of use, robust community, etc. Big thanks to the Chart.js team for their work!
I wound up building an open-source web service for rendering Chart.js to images for embedding in static contexts without JS support such as email and chat: https://github.com/typpo/quickchart. Maybe some reading this thread will find it useful.
I've been using Uber's graphing libraries, and they're nothing short of stunning.[1] It's easy to get started, and customizing or extending functionality is straightforward, with myriad example to help. And charting is rendering agnostic. SVG? Canvas? You choose. My only gripe is the lack of TypeScript support. I won't touch vanillaJS with a 20 foot pole if I can help, and the the missing type annotations can be painful.
[1] https://deck.gl/ (The navbar dropdown lists all of their libraries for easy exploration.)
Over the years, I've narrowed my focus to: d3.js via dc.js and crossfilter.js.
This 3 punch combo creates an incredible user experience. The only downside is that dc.js doesn't have all the charts. The interactivity with the basic charts they do have is worth the absence of other types of charts.
44 comments
[ 3.3 ms ] story [ 100 ms ] threadThis is how the Chart.js code begins:
I have no idea how to read this, what this means and how to invoke a construct like this.Change to ES modules would be welcome though.
If the library is imported in the way that the article recommends in step two, it's not actually loaded as an ES6 module. This code checks to see if we're currently acting as a module and accordingly makes sure that the library is available as a global object. See this link for some examples: https://devhints.io/umdjs
> I have no idea how to read this ...
I tried to add some comments [0] which will hopefully help!
[0] https://gist.github.com/tjwds/8883b20d5981518bad66497f0466ac...
As a module:
As a module dependency:> Yes, this is the point of that code. It's boilerplate to ensure the module loads in different environments.
but the UDM header does not allow the module to load in JS modules. So I'm not quite sure what you meant actually. The header does nothing for standard modules.
Please file an issue! Libraries need to upgrade to JS modules ASAP.
Nowadays I prefer Apexcharts.js, which renders to SVG.
https://github.com/apexcharts/apexcharts.js (MIT License)
Also, if you're interested in realtime charts, here's a related plugin I've seen: https://github.com/nagix/chartjs-plugin-streaming
I think the other advantage SVG has can be is if you want to do some advanced interactivity. That can sometimes be easier in SVG.
options: { devicePixelRatio: 2 }
here is how it performs vs Chart.js:
https://github.com/leeoniya/uPlot#performance
i will add Apex charts to the bench list in a day or so
i think the only practical way to get acceptable perf with SVG is to simplify the paths via something like https://mourner.github.io/simplify-js/
Thanks for creating this :)
is this mentioned anywhere in the docs? seems non-obvious.
https://github.com/jwilber/roughViz
I wound up building an open-source web service for rendering Chart.js to images for embedding in static contexts without JS support such as email and chat: https://github.com/typpo/quickchart. Maybe some reading this thread will find it useful.
[1] https://deck.gl/ (The navbar dropdown lists all of their libraries for easy exploration.)
It's a popular framework, so a lot of my questions were answered on Stack Overflow.
This 3 punch combo creates an incredible user experience. The only downside is that dc.js doesn't have all the charts. The interactivity with the basic charts they do have is worth the absence of other types of charts.