有关高位图表,请参见下面的json {“ chart”:{“ type”:“ column”},“贷方”:{“ enabled”:true,“ href”:“#”,“ position”:{“ align”:“ right”,“ verticalAlign” :“底部”,“ y”:0},“文本”:“ www.midasplus.com”},“系列”:[{“颜色”:{“ linearGradient”:{“ x1”:1,“ x2” :0,“ y1”:0,“ y2”:1},“停止”:[[0,“#9a1919”],[“ 0.25”,“#9a1919”],[“ 0.5”,“#9a7319” ],[“ 0.75”,“#9a1919”],[1,“#9a1919”]]},“数据”:[“ -1.03”,“-3.01”,“-2.25”,“ 0.63”,“- 1.07“,” 1.14“,”-0.38“,” 2.03“,”-2.07“,”-3.55“,”-3.99“,”-0.41“],” negativeColor“:{” linearGradient“:{” x1“ :-1,“ x2”:0,“ y1”:0,“ y2”:-1},“停止”:[[0,“#199A19”],[“ 0.25”,“#199A19”],[ “ 0.5”,“#00CC00”],[“ 0.75”,“#199A19”],[1,“#199A19”]]},“ showInLegend”:“ false”}],“ title”:{“ text” :“ Control Chart”},“ xAxis”:{“类别”:[“ Q3 2013”,“ Q4 2013”,“ Q1 2014”,“ Q2 2014”,“ Q3 2014”,“ Q4 2014”,“ Q1 2015 “,” 2015年第二季度“,” 2015年第三季度“,” 2015年第四季度“,” 2016年第一季度“,” 2016年第二季度“]}}
在此,我需要更改“数据”:[“ -1.03”,“-3.01”,“-2.25”,“ 0.63”,“-1.07”,“ 1.14”,“-0.38”,“使用JavaScript,将2.03“,”-2.07“,”-3.55“,”-3.99“,”-0.41“]字符串数组值转换为同一json中的整数数组。
答案 0 :(得分:0)
const data = {"chart": {"type": "column"},"credits": {"enabled": true,"href": "#","position": {"align": "right","verticalAlign": "bottom","y": 0},"text": "www.midasplus.com"},"series": [{"color": {"linearGradient": {"x1": 1,"x2": 0,"y1": 0,"y2": 1},"stops": [[0,"#9a1919"],["0.25","#9a1919"],["0.5","#9a7319"],["0.75","#9a1919"],[1,"#9a1919"]]},"data": ["-1.03","-3.01","-2.25","0.63","-1.07","1.14","-0.38","2.03","-2.07","-3.55","-3.99","-0.41"],"negativeColor": {"linearGradient": {"x1": -1,"x2": 0,"y1": 0,"y2": -1},"stops": [[0,"#199A19"],["0.25","#199A19"],["0.5","#00CC00"],["0.75","#199A19"],[1,"#199A19"]]},"showInLegend": "false"}],"title": {"text": "Control Chart"},"xAxis": {"categories": ["Q3 2013","Q4 2013","Q1 2014","Q2 2014","Q3 2014","Q4 2014","Q1 2015","Q2 2015","Q3 2015","Q4 2015","Q1 2016","Q2 2016"]} }
const floatArr = data.series[0].data.map(item => {
return parseFloat(item)
})
如果您希望将它们作为整数,请将函数parseInt(item, 10)
与parseFloat(item)
一起使用。