正在跟踪轻量级图表的文档,并尝试在repl上用Node.js创建我的第一个图表。我有带有轻量级图表的package.json,并在repl中运行npm install lightweight-charts,并下载了轻量级图表。然而,当我运行代码时,我会得到以下错误:SyntaxError: Named export 'createChart' not found. The requested module 'lightweight-charts' is a CommonJS module, which may not support all module.exports as named exports.
我不知道从这里往哪里走。
发布于 2022-06-20 20:40:50
尝试用LightweightCharts.createChart(...)代替
发布于 2022-06-21 08:51:31
这是一个完整的测试页面。注意加载库的第一个脚本(一旦用npm run build编译)
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width,initial-scale=1.0,maximum-scale=1.0,minimum-scale=1.0">
<title>Debug page</title>
<script type="text/javascript" src="./dist/lightweight-charts.standalone.development.js"></script>
</head>
<body style="padding: 0; margin: 0;">
<div id="container1"></div>
<script type="text/javascript">
const chart = LightweightCharts.createChart(document.body, { width: 400, height: 300 });
const lineSeries = chart.addLineSeries();
lineSeries.setData([
{ time: '2019-04-11', value: 80.01 },
{ time: '2019-04-12', value: 96.63 },
{ time: '2019-04-13', value: 76.64 },
{ time: '2019-04-14', value: 81.89 },
{ time: '2019-04-15', value: 74.43 },
{ time: '2019-04-16', value: 80.01 },
{ time: '2019-04-17', value: 96.63 },
{ time: '2019-04-18', value: 76.64 },
{ time: '2019-04-19', value: 81.89 },
{ time: '2019-04-20', value: 74.43 },
]);
</script>
</body>
</html>https://stackoverflow.com/questions/72692436
复制相似问题