Highcharts series data not working

ぃ、小莉子 提交于 2019-12-12 03:38:56

问题


My existing array is as below:

"Issues": [{
    "Id": null,
    "Key": null,
    "Values": [{
        "Key": "Display Name",
        "Value": "Rya"
    }, {
        "Key": "UserName",
        "Value": "RH"
    }, {
        "Key": "Count",
        "Value": "350"
    }]
}, {
    "Id": null,
    "Key": null,
    "Values": [{
        "Key": "Display Name",
        "Value": "Mike"
    }, {
        "Key": "UserName",
        "Value": "ML"
    }, {
        "Key": "Count",
        "Value": "90"
    }]
}]

My desired array:

[{
    name: 'Rya', 
    value: 350
}, {
    name: 'Mike', 
    value: 90
}]

What I tried:

Data.Issues.map(o=> o.Values.reduce((acc, {Key, Value}) =>
                                       (acc[Key] = Value, acc), {}));

this.donughtChartData1 = this.donughtChartData.map( ({UserName, Count}) => 
    ({ name: UserName, value: Count}) );

But this gives me:

[{
    "name": "RHanney",
    "value": "350"
}, { 
    "name": "MLuckenbill", 
    "value": "90"
}]

This has quotes and my highcharts doesn't work if there are quotes.


回答1:


In the last line of your code, add a + before Count so it gets converted to a number:

// ...
({ name: UserName, value: +Count}) );

How adding one character can bring the solution :-)



来源:https://stackoverflow.com/questions/43352917/highcharts-series-data-not-working

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!