问题
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