uPlot does not take typed arrays as data
See original GitHub issueThis is a comment I got on stack overflow, when my example failed to render: https://stackoverflow.com/questions/72880591/using-uplot-with-svelte-does-not-render/72881761#72881761
I see that it does take typed arrays in the demo (https://github.com/leeoniya/uPlot/blob/master/demos/area-fill.html), but not when used as an npm package. Which is very confusing 🤔
Another (simpler) example is to use Vite with vanilla js, and the following files:
index.html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<title>Vite App</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<link rel="icon" type="image/svg+xml" href="favicon.svg" />
<link rel="stylesheet" href="node_modules/uplot/dist/uPlot.min.css"/>
</head>
<body>
<div id="app"></div>
<script type="module" src="/src/main.ts"></script>
</body>
</html>
main.ts
import uPlot from 'uplot';
let data = [
new Float32Array([1., 2., 3., 4., 5.]),
new Float32Array([1., 3., 2., 5., 4.]),
];
const opts = {
width: 600,
height: 300,
scales: {x: {time: false}},
series: [
{label: "x"},
{label: "y", stroke: "red"},
],
};
new uPlot(opts, data, document.body);
If I remove Float32Array
things get rendered properly. npm
installs uplot
version 1.6.21`.
Issue Analytics
- State:
- Created a year ago
- Comments:7 (4 by maintainers)
Top Results From Across the Web
scatter plots · Issue #107 · leeoniya/uPlot - GitHub
I don't understand why this would need a different data ... nice benefit is we can use typed arrays too, and the value...
Read more >Typed arrays - Binary data in the browser - web.dev
Typed Arrays are a relatively recent addition to browsers, born out of the need to have an efficient way to handle binary data...
Read more >Using uPlot with svelte, does not render - Stack Overflow
uPlot does not take typed arrays as data; The reactive statement is a bit pointless, as it only triggers in a meaningful once...
Read more >20. Typed Arrays - Exploring JS
Typed Arrays are an ECMAScript 6 API for handling binary data. ... a normal Array, but only allows a single type for its...
Read more >ArrayBuffer, binary arrays - The Modern JavaScript Tutorial
In web-development we meet binary data mostly while dealing with files (create, upload, download). Another typical use case is image ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
fixed in f0af226e735bafb21feb18755cb95dc1dbdcc7f1
ah, okay. if i omit
AlignedData
, then it complains. i can add TypedArray[] to the signature