Javascript 如何在highchart中传递数组??
我刚开始使用highcharts,我被困在这里- 我有两个数组,名为-Javascript 如何在highchart中传递数组??,javascript,php,highcharts,Javascript,Php,Highcharts,我刚开始使用highcharts,我被困在这里- 我有两个数组,名为-js_平台,js_totalTest,我正在从数据库中获取它们 生成图表的代码为- <!DOCTYPE html> <body> <script src="http://code.jquery.com/jquery-1.11.0.min.js"></script> <script src="http://code.highcharts.com/hig
js_平台,js_totalTest
,我正在从数据库中获取它们
生成图表的代码为-
<!DOCTYPE html>
<body>
<script src="http://code.jquery.com/jquery-1.11.0.min.js"></script>
<script src="http://code.highcharts.com/highcharts.js"></script>
<script src="http://code.highcharts.com/modules/exporting.js"> </script>
<script>
$(function () {
js_platform = <?php echo json_encode($platform); ?>;
js_totalTest = <?php echo json_encode($totalTest); ?>;
$('#container').highcharts({
chart: {
type: 'column'
},
title: {
text: 'Overall avalibility of testcases on each platform'
},
xAxis: {
categories: js_platform
},
yAxis: {
min: 0,
title: {
text: 'Total fruit consumption'
},
stackLabels: {
enabled: true,
style: {
fontWeight: 'bold',
color: (Highcharts.theme && Highcharts.theme.textColor) || 'gray'
}
}
},
legend: {
align: 'right',
x: -70,
verticalAlign: 'top',
y: 20,
floating: true,
backgroundColor: (Highcharts.theme && Highcharts.theme.legendBackgroundColorSolid) || 'white',
borderColor: '#CCC',
borderWidth: 1,
shadow: false
},
tooltip: {
formatter: function() {
return '<b>'+ this.x +'</b><br/>'+
this.series.name +': '+ this.y +'<br/>'+
'Total: '+ this.point.stackTotal;
}
},
plotOptions: {
column: {
stacking: 'normal',
dataLabels: {
enabled: true,
color: (Highcharts.theme && Highcharts.theme.dataLabelsColor) || 'white',
style: {
textShadow: '0 0 3px black, 0 0 3px black'
}
}
}
},
series: [{
name: 'John',
data: [5, 3, 4, 7, 2]
}, {
name: 'Jane',
data: [2, 2, 3, 2, 1]
}, {
name: 'Joe',
data: [3, 4, 4, 2, 5]
}]
});
});
</script>
<div id="container" style="min-width: 310px; height: 400px; margin: 0 auto"></div>
</body>
</html>
$(函数(){
js_平台=;
js_totalTest=;
$(“#容器”)。高图({
图表:{
类型:“列”
},
标题:{
文本:“每个平台上测试用例的总体可用性”
},
xAxis:{
类别:js_平台
},
亚克斯:{
分:0,,
标题:{
正文:“水果总消费量”
},
堆叠标签:{
启用:对,
风格:{
fontWeight:'粗体',
颜色:(Highcharts.theme&&Highcharts.theme.textColor)| |“灰色”
}
}
},
图例:{
对齐:“右”,
x:-70,
垂直排列:“顶部”,
y:20,
浮动:是的,
背景色:(Highcharts.theme&&Highcharts.theme.legendBackgroundColorSolid)| |白色,
边框颜色:“#CCC”,
边框宽度:1,
影子:错
},
工具提示:{
格式化程序:函数(){
返回“+this.x+”
+
this.series.name+':'+this.y+'
+
“总计:”+this.point.stackTotal;
}
},
打印选项:{
专栏:{
堆叠:“正常”,
数据标签:{
启用:对,
颜色:(Highcharts.theme&&Highcharts.theme.dataLabelsColor)| |“白色”,
风格:{
textShadow:'0 0 3px黑色,0 0 3px黑色'
}
}
}
},
系列:[{
姓名:'约翰',
数据:[5,3,4,7,2]
}, {
姓名:'简',
数据:[2,2,3,2,1]
}, {
名字:'乔',
数据:[3,4,4,2,5]
}]
});
});
现在,对于这个系列,我想发送js_totalTest的数组值
在这里,如果我执行类似于**series:[{data:[js\u totalTest]}]**
的操作,它不会显示任何内容
我怎么能做到?
请引导。像这样试试。
您的数组js_totalTest
包含数据和名称值
循环数组数据
var arr = [];
for(var i=0;i<js_totalTest.length;i++)
{
arr[i] = {};
arr[i]['name'] = ''; //Here push your series name field in your example "John, Jane etc"
for(var j=0;j<s.length;j++)
{
arr_data.push(parseInt(s[j]));
}
arr[i]['data'] = parseInt('') ; // Here push your series data (Eg: 5 ,3 , etc.)
}
做一些类似于-
series:
[{
data: [<?php echo join($totalTest, ',') ?>]
}]
系列:
[{
数据:[]
}]
请参阅链接()您必须以json格式传递序列数据。MM…是的,看起来像是,我只希望js_的所有值在序列中进行测试。我厌倦了这段代码,但它不起作用-
var mySeries=[];对于(var i=0;i嘿,我没有得到arr[i]['name']=''//这里推送您的序列名称字段
arr[i]['data']=parseInt('');//这里推送您的系列数据
我更新了我的后期检查。打印您的数组格式,并检查数据以何种方式来。@Gowiriecho json_encode($totalTest)的输出代码>类似于-[“1”、“1”、“4”、“193”、“98”、“218”、“98”、“471”、“9”、“201”、“18”、“144”、“2”、“163”、“30”、“163”、“90”、“84”、“47”、“428”、“397”、“74”、“4”、“1”、“1”、“1”、“979”、“297”、“264”、“418”、“316”、“280”、“6”、“4”、“1”、“1”、“1”、“2”、“52”、“201”、“80”、“316”、“433”、“691”、“496”、“767”、“610”、“1”、“20”]我在输出中没有看到任何内容。没有图表
series:
[{
data: [<?php echo join($totalTest, ',') ?>]
}]