I need to include my json String output to a highcharts --pie chart category but chart is not loading properly
我需要将我的json String输出包含到highcharts --pie图表类别中,但图表未正确加载
This is my JSON string
这是我的JSON字符串
var json = {"{\"name\":\"BillToMobile\"}":{"y":2.35},"{\"name\":\"Telenav\"}":{"y":13.59}}
Highcharts.chart('container', {
chart: {
plotBackgroundColor: null,
plotBorderWidth: null,
plotShadow: false,
type: 'pie'
},
title: {
text: ''
},
tooltip: {
pointFormat: '{series.name}: <b>{point.percentage:.1f}%</b>'
},
plotOptions: {
pie: {
allowPointSelect: true,
cursor: 'pointer',
dataLabels: {
enabled: true,
format: '<b>{point.name}</b>: {point.percentage:.1f} %',
style: {
color: (Highcharts.theme && Highcharts.theme.contrastTextColor) || 'black'
}
}
}
},
series: [{
name: 'Brands',
colorByPoint: true,
data: json
}]
});
Below is the chart what I'm getting when loading this jsonstring. Can any one help me with this because I'm new to this.Thanks in advance.
下面是我在加载这个jsonstring时得到的图表。任何人都可以帮助我,因为我是新手。谢谢你。
1 个解决方案
#1
2
Try formatting your json this way
尝试以这种方式格式化你的json
var json = [{name: "BillToMobile", y: 2.35}, {name: "Telenav", y: 13.59}]
To convert the json you have you can use this:
要转换json,你可以使用:
ES5 or earlier
ES5或更早版本
var properJson = [];
for (var i in json) {
var item = JSON.parse(i);
for (var j in json[i]) {
item[j] = json[i][j];
}
properJson.push(item);
}
ES6
var properJson = [];
for (var i in json) {
var item = JSON.parse(i);
Object.assign(item, json[i]);
properJson.push(item);
}
#1
2
Try formatting your json this way
尝试以这种方式格式化你的json
var json = [{name: "BillToMobile", y: 2.35}, {name: "Telenav", y: 13.59}]
To convert the json you have you can use this:
要转换json,你可以使用:
ES5 or earlier
ES5或更早版本
var properJson = [];
for (var i in json) {
var item = JSON.parse(i);
for (var j in json[i]) {
item[j] = json[i][j];
}
properJson.push(item);
}
ES6
var properJson = [];
for (var i in json) {
var item = JSON.parse(i);
Object.assign(item, json[i]);
properJson.push(item);
}