A Beginner’s Guide to Chart.js
stanleyulili.com
stanleyulili.com
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.
This is how the Chart.js code begins:
(function (global, factory) {
typeof exports === 'object' && typeof module !==
'undefined' ? module.exports = factory() :
typeof define === 'function' && define.amd ?
define(factory) :
(global.Chart = factory());
}(this, (function () { 'use strict';
... now comes all the code ...
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:
<script type="module" src="Chart.js"></script>
As a module dependency: import * as chart from 'Chart.js';> 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.
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.)
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.
It's a popular framework, so a lot of my questions were answered on Stack Overflow.