javascript - Highchart 的错误:Uncaught SyntaxError: Unexpected token for
问题描述
所以我想做的是我试图根据我在数组中的数据在特定的 X 值上创建 Plotline。
我有 2 个数据数组:
featurex = [95,193,295,393,480,587,700,799,912,1015,1123,1230,1336,1443,1554] ;
featurey = [0,0,0,0,0,3,0,0,0,0,0,0,0,0,0];
现在我想要做的是我试图在 X 轴上绘制一条情节线,其中我的 Y 轴为 3 如您在上面看到的。
我能够静态地做到这一点,但我希望它是动态的。
这是我正在使用的 Highchart 的代码。
Highcharts.chart('ppg', {
chart: {
type: 'line'
},
title: {
text: 'ECG Data'
},
subtitle: {
text: ''
},
xAxis:
for( i=0; i<featurex.length; i++)
{
if (featurey[i] == 3) {
plotLines: [
{
value: featurex[i],
color: '#005a9b94',
dashStyle: 'shortdash',
width: 100,
},
}
},
crosshair: false
},
yAxis: {
title: {
text: 'Peaks'
}
},
tooltip: {
enable: false
},
plotOptions: {
column: {
pointPadding: 0.2,
borderWidth: 0
}
},
series: [{
name: '',
lineWidth: 2,
data: yData,
animation: {
duration: 5000
}
},
{ type: 'scatter',
name: 'Installation',
data: zip(xPeak, yPeak),
animation: {
duration: 5200
}
},
]
});
});
});
</script>
这里的 Plotline 代码Xaxis
是主要关注的领域。它给我一个错误:
未捕获的 SyntaxError:意外的令牌
请指导我做错了什么。
非常感谢任何帮助。谢谢。
解决方案
问题就在这里,
xAxis:
for( i=0; i<featurex.length; i++)
以上不是有效的 javascript 语法。
如果您需要动态的绘图线,请传递一个返回数组的函数
xAxis: {
plotLines: generateDynamicPlotLines(),
}
你的功能会是这样的,
function generateDynamicPlotLines() {
const plotLines = [];
for(var i=0; i<featurex.length; i++) {
if (featurey[i] == 3) {
plotLines.push({
value: featurex[i],
color: '#005a9b94',
dashStyle: 'shortdash',
width: 100,
});
}
}
return plotLines;
}
推荐阅读
- excel - 将图表从 Excel 复制到 PPT
- powershell - 如果需要,通过替换前两个字符来更正子文件夹名称
- mysql - MySQL 8.0.21.0 - 安装期间数据库初始化错误
- javascript - 刽子手游戏图像仅 javascript
- flutter - 如何在颤动中更改网格视图的项目
- r - 分组变量以创建子集
- python - 如何在第一个元素满足要求的numpy数组中获取特定的行或列?
- vue.js - 如何解决 Jest 测试中的 toUpperCase 问题?
- vue-formulate - 如何从另一个按钮验证 vue-formulate 表单
- heroku - 错误太多