数组作为 Highcharts 系列不起作用
Array as Highcharts series isn't working
我在尝试将数组作为参数传递到 highcharts 时遇到问题。
我是 following -(Gowri 的)建议,但我没有运气。即使在我的图例中正确呈现了用户名(故意去掉姓氏),实际值也完全遗漏了,因此我的图表总是空的,即没有条形...
即使数组已正确填充,并且用户名在图例中显示正常,但它没有显示任何内容
我也在 jsfiddle 上发布了示例,但很抱歉无法正确渲染
jsfiddle(包含 json2 源)
HTML:
<script src="http://code.highcharts.com/highcharts.js"></script>
<center>
<div id='searchdiv'></div>
<script type='text/javascript'>
setTimeout(function() {
Chart_Weekly_Trends_Bar('weeklypackagingtrends', 'Passed Approval', ['03/01/2014', '10/01/2014', '17/01/2014', '24/01/2014', '31/01/2014', '07/02/2014', '14/02/2014', '21/02/2014', '28/02/2014', '07/03/2014'], 'Number of Apps', 'No of Apps', ['Andr', 'Ch', 'Gra', 'Gul', 'Hora', 'Jhan', 'Krist', 'Man', 'Mike', 'Phil', 'Tris'], ['0,0,0,0,0,0,0,0,0,0', '0,0,0,0,0,0,0,0,0,0', '0,0,0,0,0,0,0,0,0,0', '0,0,0,0,0,0,0,0,0,0', '0,0,0,0,0,0,0,0,0,0', '0,0,0,0,0,0,0,0,0,0', '0,0,0,0,0,1,2,1,0,2', '0,0,0,0,0,0,0,0,0,0', '0,0,0,2,0,0,0,0,0,0', '0,0,0,0,2,1,0,0,2,1', '0,0,0,0,0,0,0,0,0,0'])
}, 100);
</script>
Javascript:
function Chart_Weekly_Trends_Bar(DIVID, TITLE, CATEGORIES, yAxisLabel, Tooltip, ANALYSTS_NAMES, ANALYSTS_DATA) {
var Param_CATEGORIESS = JSON.stringify(CATEGORIES);
var data_CATEGORIESS = JSON.parse(Param_CATEGORIESS);
var arr = [];
for (var i = 0; i < ANALYSTS_NAMES.length; i++) {
arr[i] = {};
arr[i]['name'] = ANALYSTS_NAMES[i]; //Here push your series name field in your example "John, Jane etc"
arr[i]['data'] = ANALYSTS_DATA[i]; //Here push your series name field in your example "John, Jane etc"
}
//arr = arr;
var Param_arr = JSON.stringify(arr);
var data_arr = JSON.parse(Param_arr);
$("#" + DIVID).highcharts({
chart: {
type: 'column',
height: 450,
width: 800,
renderTo: 'weeklypackagingtrends'
},
title: {
text: TITLE
},
xAxis: {
categories: data_CATEGORIESS,
//categories: ['20-10-2015','21-10-2015'],
tickInterval: .5,
tickmarkPlacement: 'on',
gridLineWidth: .5,
min: 0,
max: 9,
labels: {
style: {
fontSize: '9px'
}
}
},
yAxis: {
opposite: true,
min: 0,
title: {
text: yAxisLabel
}
},
tooltip: {
headerFormat: '<span style="font-size:20px">{point.key}</span><table width=150px>',
pointFormat: '<tr><td style="color:{series.color};padding:0">{series.name}: </td>' +
'<td style="padding:0"><b>{point.y:1f} </b></td></tr>',
footerFormat: '</table>',
shared: true,
useHTML: true,
animation: true
},
plotOptions: {
column: {
pointPadding: 0.2,
borderWidth: 0
}
},
scrollbar: {
enabled: true
},
series: data_arr,
navigation: {
buttonOptions: {
verticalAlign: 'bottom',
y: -20,
height: 30,
theme: {
'stroke-width': 1,
stroke: 'silver',
r: 0,
states: {
hover: {
fill: '#bada55'
},
select: {
stroke: '#039',
fill: '#bada55'
}
}
}
}
},
credits: {
enabled: false
}
});
}
您目前正在将数据数组作为字符串数组发送:
['0,0,0,0,0,0,0,0,0,0', '0,0,0,0,0,0,0,0,0,0', '0,0,0,0,0,0,0,0,0,0', '0,0,0,0,0,0,0,0,0,0', '0,0,0,0,0,0,0,0,0,0', '0,0,0,0,0,0,0,0,0,0', '0,0,0,0,0,1,2,1,0,2', '0,0,0,0,0,0,0,0,0,0', '0,0,0,2,0,0,0,0,0,0', '0,0,0,0,2,1,0,0,2,1', '0,0,0,0,0,0,0,0,0,0']
你需要的是数组的数组:
[[0,0,0,0,0,0,0,0,0,0], [0,0,0,0,0,0,0,0,0,0], [0,0,0,0,0,0,0,0,0,0], [0,0,0,0,0,0,0,0,0,0], [0,0,0,0,0,0,0,0,0,0], [0,0,0,0,0,0,0,0,0,0], [0,0,0,0,0,1,2,1,0,2], [0,0,0,0,0,0,0,0,0,0], [0,0,0,2,0,0,0,0,0,0], [0,0,0,0,2,1,0,0,2,1], [0,0,0,0,0,0,0,0,0,0]]
示例:
我在尝试将数组作为参数传递到 highcharts 时遇到问题。 我是 following -(Gowri 的)建议,但我没有运气。即使在我的图例中正确呈现了用户名(故意去掉姓氏),实际值也完全遗漏了,因此我的图表总是空的,即没有条形...
即使数组已正确填充,并且用户名在图例中显示正常,但它没有显示任何内容
我也在 jsfiddle 上发布了示例,但很抱歉无法正确渲染
jsfiddle(包含 json2 源)
HTML:
<script src="http://code.highcharts.com/highcharts.js"></script>
<center>
<div id='searchdiv'></div>
<script type='text/javascript'>
setTimeout(function() {
Chart_Weekly_Trends_Bar('weeklypackagingtrends', 'Passed Approval', ['03/01/2014', '10/01/2014', '17/01/2014', '24/01/2014', '31/01/2014', '07/02/2014', '14/02/2014', '21/02/2014', '28/02/2014', '07/03/2014'], 'Number of Apps', 'No of Apps', ['Andr', 'Ch', 'Gra', 'Gul', 'Hora', 'Jhan', 'Krist', 'Man', 'Mike', 'Phil', 'Tris'], ['0,0,0,0,0,0,0,0,0,0', '0,0,0,0,0,0,0,0,0,0', '0,0,0,0,0,0,0,0,0,0', '0,0,0,0,0,0,0,0,0,0', '0,0,0,0,0,0,0,0,0,0', '0,0,0,0,0,0,0,0,0,0', '0,0,0,0,0,1,2,1,0,2', '0,0,0,0,0,0,0,0,0,0', '0,0,0,2,0,0,0,0,0,0', '0,0,0,0,2,1,0,0,2,1', '0,0,0,0,0,0,0,0,0,0'])
}, 100);
</script>
Javascript:
function Chart_Weekly_Trends_Bar(DIVID, TITLE, CATEGORIES, yAxisLabel, Tooltip, ANALYSTS_NAMES, ANALYSTS_DATA) {
var Param_CATEGORIESS = JSON.stringify(CATEGORIES);
var data_CATEGORIESS = JSON.parse(Param_CATEGORIESS);
var arr = [];
for (var i = 0; i < ANALYSTS_NAMES.length; i++) {
arr[i] = {};
arr[i]['name'] = ANALYSTS_NAMES[i]; //Here push your series name field in your example "John, Jane etc"
arr[i]['data'] = ANALYSTS_DATA[i]; //Here push your series name field in your example "John, Jane etc"
}
//arr = arr;
var Param_arr = JSON.stringify(arr);
var data_arr = JSON.parse(Param_arr);
$("#" + DIVID).highcharts({
chart: {
type: 'column',
height: 450,
width: 800,
renderTo: 'weeklypackagingtrends'
},
title: {
text: TITLE
},
xAxis: {
categories: data_CATEGORIESS,
//categories: ['20-10-2015','21-10-2015'],
tickInterval: .5,
tickmarkPlacement: 'on',
gridLineWidth: .5,
min: 0,
max: 9,
labels: {
style: {
fontSize: '9px'
}
}
},
yAxis: {
opposite: true,
min: 0,
title: {
text: yAxisLabel
}
},
tooltip: {
headerFormat: '<span style="font-size:20px">{point.key}</span><table width=150px>',
pointFormat: '<tr><td style="color:{series.color};padding:0">{series.name}: </td>' +
'<td style="padding:0"><b>{point.y:1f} </b></td></tr>',
footerFormat: '</table>',
shared: true,
useHTML: true,
animation: true
},
plotOptions: {
column: {
pointPadding: 0.2,
borderWidth: 0
}
},
scrollbar: {
enabled: true
},
series: data_arr,
navigation: {
buttonOptions: {
verticalAlign: 'bottom',
y: -20,
height: 30,
theme: {
'stroke-width': 1,
stroke: 'silver',
r: 0,
states: {
hover: {
fill: '#bada55'
},
select: {
stroke: '#039',
fill: '#bada55'
}
}
}
}
},
credits: {
enabled: false
}
});
}
您目前正在将数据数组作为字符串数组发送:
['0,0,0,0,0,0,0,0,0,0', '0,0,0,0,0,0,0,0,0,0', '0,0,0,0,0,0,0,0,0,0', '0,0,0,0,0,0,0,0,0,0', '0,0,0,0,0,0,0,0,0,0', '0,0,0,0,0,0,0,0,0,0', '0,0,0,0,0,1,2,1,0,2', '0,0,0,0,0,0,0,0,0,0', '0,0,0,2,0,0,0,0,0,0', '0,0,0,0,2,1,0,0,2,1', '0,0,0,0,0,0,0,0,0,0']
你需要的是数组的数组:
[[0,0,0,0,0,0,0,0,0,0], [0,0,0,0,0,0,0,0,0,0], [0,0,0,0,0,0,0,0,0,0], [0,0,0,0,0,0,0,0,0,0], [0,0,0,0,0,0,0,0,0,0], [0,0,0,0,0,0,0,0,0,0], [0,0,0,0,0,1,2,1,0,2], [0,0,0,0,0,0,0,0,0,0], [0,0,0,2,0,0,0,0,0,0], [0,0,0,0,2,1,0,0,2,1], [0,0,0,0,0,0,0,0,0,0]]
示例: