【发布时间】:2018-09-20 05:10:38
【问题描述】:
我在字符串文字中有一个 json 对象
chartOptionsStr = `{
"chart": {
"type": "line"
},
"title": {
"text": ""
},
"subtitle": {
"text": ""
},
"xAxis": {
"categories": ${categories},
"labels": {
"align":"right",
"rotation":"0"
}
},
"yAxis": {
"title": {
"text": "Number of Messages"
},
"tickInterval": 5
},
"plotOptions": {
"line": {
"dataLabels": {
"enabled": false
},
"enableMouseTracking": true
}
},
"series": [{
"name": "Sent",
"data": [37.0, 26.9, 30.5, 47.5]
}, {
"name": "Delivered",
"data": [27.0, 16.9, 20.5, 37.5]
}, {
"name": "Open",
"data": [27.0, 16.9, 20.5, 37.5]
}]
}`;
在这个对象中我需要传递一个数组类别
["19.Dec","12.Jan","15.Feb","28 Mar"] as a dynamic value using ${categories}
但问题是当我控制这个 chartOptionsStr 时,它显示以下输出:
{
"chart": {
"type": "line"
},
"title": {
"text": ""
},
"subtitle": {
"text": ""
},
"xAxis": {
"categories": 12.Dec,18.Dec,20.Dec,1.Jan,
"labels": {
"align":"right",
"rotation":"0"
}
},
"yAxis": {
"title": {
"text": "Number of Messages"
},
"tickInterval": 5
},
"plotOptions": {
"line": {
"dataLabels": {
"enabled": false
},
"enableMouseTracking": true
}
},
"series": [{
"name": "Sent",
"data": [37.0, 26.9, 30.5, 47.5]
}, {
"name": "Delivered",
"data": [27.0, 16.9, 20.5, 37.5]
}, {
"name": "Open",
"data": [27.0, 16.9, 20.5, 37.5]
}]
}
作为单个值附加的字符串数组。
是否有任何机构对此有解决方案?
我正在尝试从角度服务中获取 highcharts 的类别。所以这个值是动态的。
【问题讨论】:
-
使用 JSON.parse 将字符串转换为对象并分配类别。如果您想再次使用 JSON.stringify() 转换为字符串格式
标签: javascript arrays angular highcharts ecmascript-6