uPlot README

The project's README from github.com/leeoniya/uPlot. As one markdown file: README.md.

uPlot logo μPlot

A small (~50 KB min), fast chart for time series, lines, areas, ohlc & bars (MIT Licensed)


Introduction

uPlot is a fast, memory-efficient Canvas 2D-based chart for plotting time series, lines, areas, ohlc & bars. From a cold start it can create an interactive chart containing 166,650 data points in 25ms, scaling linearly at ~100,000 pts/ms afterwards. In addition to fast initial render, the zooming and cursor performance is by far the best of any similar charting lib; at ~50 KB, it's likely the smallest and fastest time series plotter that doesn't make use of context-limited WebGL shaders or WASM, both of which have much higher startup cost and code size.

In most sane cases, you can live-stream data with uPlot at 60fps, though it may begin to struggle beyond 100k in-view points. When updating 3,600 points at 60fps, uPlot uses 10% CPU and 12.3MB RAM. The next fastest Canvas-based libs (Chart.js and ECharts) use 40% / 77MB and 70% / 85MB, respectively. If you need to stream, give unclog your rendering pipeline a try. If that does not help, consider reducing the update frequency or switch to a WebGL/WebGPU solution, like danchitnis/webgl-plot, huww98/TimeChart, epezent/implot.


uPlot Chart


Features


Non-Features

In order to stay lean, fast and focused the following features will not be added:


Documentation (WIP)

The docs are a perpetual work in progress, it seems. Start with /docs/README.md for a conceptual overview. The full API is further documented via comments in /dist/uPlot.d.ts. Additionally, an ever-expanding collection of runnable /demos covers the vast majority of uPlot's API.


Third-party Integrations


Performance

Benchmarks done on this hardware:

uPlot Performance

Full size: https://leeoniya.github.io/uPlot/demos/multi-bars.html

Raw data: https://github.com/leeoniya/uPlot/blob/master/bench/results.json

| lib                    | size    | done    | js,rend,paint,sys | heap peak,final | mousemove (10s)     |
| ---------------------- | ------- | ------- | ----------------- | --------------- | ------------------- |
| uPlot v1.6.24          | 47.9 KB |   34 ms |   51   2   1   34 |  21 MB   3 MB   |  218  360  146  196 |
| Chart.js v4.2.1        |  254 KB |   38 ms |   90   2   1   40 |  29 MB  10 MB   | 1154   46  165  235 |
| Flot v3.0.0            |  494 KB |   60 ms |  105   5   1   52 |  41 MB  21 MB   | ---                 |
| ECharts v5.4.1         | 1000 KB |   55 ms |  148   3   1   35 |  17 MB   3 MB   | 1943  444  203  208 |
| dygraphs v2.2.1        |  132 KB |   90 ms |  163   2   1   33 |  88 MB  42 MB   | 1438  371  174  268 |
| LightningChart® v4.0.2 | 1300 KB |  --- ms |  250   2   1   33 |  33 MB  13 MB   | 5390  120  128  325 |
| CanvasJS v3.7.5        |  489 KB |  130 ms |  266   4   1   35 |  98 MB  69 MB   | 1030  445   90  246 |
| dvxCharts v5.1.0       |  373 KB |  160 ms |  264  23   1   62 | 100 MB  61 MB   |  687  779  206  197 |
| Highcharts v10.3.3     |  413 KB |  --- ms |  416   7   1   38 |  97 MB  55 MB   | 1286  824  205  242 |
| Plotly.js v2.18.2      | 3600 KB |  310 ms |  655  14   1   40 | 104 MB  70 MB   | 1814  163   25  208 |
| ApexCharts v3.37.1     |  503 KB |  685 ms |  694   9   1   33 | 175 MB  46 MB   | 1708  421  106  207 |
| ZingChart v2.9.10      |  871 KB |  681 ms |  717   7   1  105 | 290 MB 195 MB   | 9021  305   41   71 |
| amCharts v5.3.7        |  625 KB |  --- ms | 1601   3   3   46 | 147 MB 121 MB   | 9171   71  460  167 |

Some libraries provide their own performance demos:

TODO (all of these use SVG, so performance should be similar to Highcharts):


Unclog your rendering pipeline

Your browser's performance is highly dependent on your hardware, operating system, and GPU drivers.

If you're using a Chromium-based browser, there are some hidden settings that can unlock significant performance improvements for Canvas2D rendering. Most of these have to do with where and how the rasterization is performed.

Head over to https://leeoniya.github.io/uPlot/demos/sine-stream.html and open up Chrome's DevTools (F12), then toggle the Performance Monitor.

Chrome DevTools Peformance Monitor

For me:

If your CPU is close to 100%, it may be rasterizing everything in the same CPU process.

Pop open chrome://gpu and see what's orange or red.

Chrome gpu

Then open chrome://flags and search for "raster" to see what can be force-enabled.

Chrome flags

YMMV!


Acknowledgements

uPlot (leeoniya/uPlot)

Searching Database…

10.6K ·GitHub
这是什么?uPlot 是一个小巧(压缩后约 50 KB)、快速、采用 MIT 许可证的 JavaScript 图表库,用于绘制时间序列、折线图、面积图、K 线图(OHLC)和柱状图,在浏览器中通过 Canvas 2D 绘制。
这是一个要加到我自己网页里的库,还是在线图表服务?它是一个客户端库,需要你添加到网页中并通过它的 API 来调用;所有内容都在浏览器里用 Canvas 2D 渲染,不涉及任何服务器。
我怎么把它加到项目里?文档写得怎么样?除了把库添加到页面之外,不需要托管或安装任何东西。文档确实还在完善中:可以先读 /docs/README.md 了解整体概念,再看看 /dist/uPlot.d.ts 里的 API 注释,然后通过 /demos 里可运行的示例来学习。
它有哪些刻意不做的事情吗?有,这是有意为之:不做数据解析、聚合或统计(需要你事先准备好数据),没有过渡和动画,不支持堆叠系列,不做坐标轴标签的防重叠处理,拖拽平移也只能通过 zoom-wheel/zoom-touch 插件实现。
作者为什么选择开发 uPlot,而不是去改进 dygraphs?他在 Dan Vanderkam 的 dygraphs 上有一个长期无人处理的 pull request(#948),正是这个被搁置的 PR 促使他着手开发 uPlot;dygraphs 至今仍被列为项目的灵感来源。
uPlot 的速度是靠 WebGL 或 WebGPU 实现的吗?不是。它纯粹使用 Canvas 2D,作者认为这正是它体积小、启动快的原因;只有当你的流式数据规模超出 Canvas 的承受能力时,才建议改用 webgl-plot、TimeChart 和 ImPlot 这类 WebGL/WebGPU 方案。
它能画平滑曲线和堆叠面积图吗?平滑样条插值可以作为可插拔的路径渲染器使用,但 README 强烈不建议使用,因为它会歪曲你的数据;堆叠系列则完全不会加入。
Creator
leeoniya
Size
12.3 MB
Stars
10.6K
Age
7y
Commits · 90 Days