1
私はこれは、このデータを使用して円グラフを作成しようとしてconsole.log();
jsonデータをハイチャートとして使用する方法円グラフ?
イムから直接であるこの
Object
negative:3
neutral:3
positive:94
のようなデータを返すAJAXリクエストを作成しましたが、私はそれが描画されないしようとすると、チャートでは、クレジットを除いて何も表示されず、コンソールにエラーも表示されません。しかし、このようなデータを手動で入力すると、
series: [{
name: 'Brands',
data: [
{ name: 'Positive', y: 94 },
{ name: 'Negative', y: 3 },
{ name: 'Neutral', y: 3 },
]
}]
でも問題ありません。
私のコードは次のとおりです。
function pieChart(data) {
// Make monochrome colors and set them as default for all pies
Highcharts.getOptions().plotOptions.pie.colors = (function() {
var colors = [],
base = Highcharts.getOptions().colors[0],
i;
for (i = 0; i < 10; i += 1) {
// Start out with a darkened base color (negative brighten), and end
// up with a much brighter color
colors.push(Highcharts.Color(base).brighten((i - 3)/7).get());
}
return colors;
}());
// Build the chart
Highcharts.chart('pieChart', {
chart: {
plotBackgroundColor: null,
plotBorderWidth: null,
plotShadow: false,
type: 'pie'
},
title: {
text: 'Browser market shares at a specific website, 2014'
},
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',
data: data
}]
});
};
あなたのjsonはどのように見えますか?サーバーからjsonを返すか、クライアント側でjsonを作成する必要があります。 –
ありがとうございます、サーバーから応答が返されています。 'console.log()'返されたデータは 'Object {positive:94、negative:3、neutral:3} 'を出力します。 – kevinabraham
ここに続けます:http://chat.stackoverflow.com/rooms/130280/http-stackoverflow- com-questions-5471291-javascript-with-jquery-click-and-doubl –