【发布时间】:2020-01-28 08:48:03
【问题描述】:
嗨,我是 Highchart、javascript、jquery、html、json 数组、json 对象的新手,我正在尝试向 json 数组中的每个 json 对象添加另一个 json 对象,是否可以在 javascript 中使用 push 来做到这一点?任何人都可以指导我,我将非常感谢您
当前 jsonArray 里面有 json 对象
[{showInLegend: false, type: 'column',
name: 'Test1',
id: 'Test1',
data: [10, 10]
},{showInLegend: false, type: 'column',
name: 'Test2',
id: 'Test2',
data: [120, 120]
},{showInLegend: false, type: 'column',
name: 'Test3',
id: 'Test3',
data: [320, 120]
}]
我想在 jsonarray 中的每个 json 对象中添加这个
tooltip: {
pointFormatter: function () {
return this.series.name + '<br/><span style="color:#273c75"><b> Amount : </b> </span>$' + this.y.toFixed(2).toString().replace(/\B(?=(\d{3})+(?!\d))/g, ",");
}
}
预期输出
[{showInLegend: false, type: 'column',
name: 'Test1',
id: 'Test1',
data: [10, 10],tooltip: {
pointFormatter: function () {
return this.series.name + '<br/><span style="color:#273c75"><b> Amount : </b> </span>$' + this.y.toFixed(2).toString().replace(/\B(?=(\d{3})+(?!\d))/g, ",");
}
}
},{showInLegend: false, type: 'column',
name: 'Test2',
id: 'Test2',
data: [120, 120],tooltip: {
pointFormatter: function () {
return this.series.name + '<br/><span style="color:#273c75"><b> Amount : </b> </span>$' + this.y.toFixed(2).toString().replace(/\B(?=(\d{3})+(?!\d))/g, ",");
}
}
},{showInLegend: false, type: 'column',
name: 'Test3',
id: 'Test3',
data: [320, 120],tooltip: {
pointFormatter: function () {
return this.series.name + '<br/><span style="color:#273c75"><b> Amount : </b> </span>$' + this.y.toFixed(2).toString().replace(/\B(?=(\d{3})+(?!\d))/g, ",");
}
}
}]
【问题讨论】:
标签: javascript arrays json highcharts