我想显示 3 个数据系列。
每当我在中设置stackSeries: true
选项时,我都会得到
Uncaught TypeError: Cannot read property '0' of undefined
或者
Uncaught TypeError: Cannot read property '1' of undefined
尝试显示数据时。
当我删除stackSeries: true
属性时,会呈现图表。怎么了?
更新
$(document).ready(function(){
var bar1 = [
<?php
if(!empty($bar1)){
$i = 0;
foreach($bar1 as $bar){
$i++;
if(!empty($bar['jobs']['date_published'])){
if($i == count($bar1))
echo '[\''.$bar['jobs']['date_published'].'\', '.$bar[0]['count'].']';
else
echo '[\''.$bar['jobs']['date_published'].'\', '.$bar[0]['count'].'], ';
}
}
}
?>
];
var bar2 = [
<?php
if(!empty($bar2)){
$i = 0;
foreach($bar2 as $bar){
$i++;
if(!empty($bar['jobs']['date_published'])){
if($i == count($bar2))
echo '[\''.$bar['jobs']['date_published'].'\', '.$bar[0]['count'].']';
else
echo '[\''.$bar['jobs']['date_published'].'\', '.$bar[0]['count'].'], ';
}
}
}
?>
];
var bar3 = [
<?php
if(!empty($bar3)){
$i = 0;
foreach($bar3 as $bar){
$i++;
if(!empty($bar['jobs']['date_published'])){
if($i == count($bar3))
echo '[\''.$bar['jobs']['date_published'].'\', '.$bar[0]['count'].']';
else
echo '[\''.$bar['jobs']['date_published'].'\', '.$bar[0]['count'].'], ';
}
}
}
?>
];
<?php
if(!empty($bar1) && !empty($bar2) && !empty($bar3))
echo 'var labels = ["Bar 1", "Bar 2", "Bar 3"];';
else if(!empty($bar1) && !empty($bar2))
echo 'var labels = ["Bar 1", "Bar 2"];';
else if(!empty($bar2) && !empty($bar3))
echo 'var labels = ["Bar 2", "Bar 3"];';
else if(!empty($bar1) && !empty($bar3))
echo 'var labels = ["Bar 1", "Bar 3"];';
else if(!empty($bar1))
echo 'var labels = ["Bar 1"];';
else if(!empty($bar2))
echo 'var labels = ["Bar 2"];';
else if(!empty($bar3))
echo 'var labels = ["Bar 3"];';
?>
optionsObj = {
//stackSeries: true,
seriesColors:[<?php if(!empty($bar1)) echo '"#4bb2c5",';
if(!empty($bar2)) echo '"#F78181",';
if(!empty($bar3)) echo '"#9AFE2E",';
echo '"#4bb2c5"'; ?>],
animate:true,
legend:{
show:true,
location:"sw",
rowSpacing:"0px",
labels:labels
},
title:{
text:"Jobs",
fontSize:"12px"
},
seriesDefaults:{
showMarker: true,
pointLabels: { show: true },
renderer: $.jqplot.BarRenderer,
rendererOptions: {
barWidth: 2
}
},
axes:{
xaxis:{
pad:1,
tickOptions:{
fontSize:"10px"
},
renderer:$.jqplot.DateAxisRenderer
},
yaxis:{autoscale: true}
},
highlighter: {show: true},
grid:{drawGridlines:true}
};
<?php $empty = false;
if(!empty($bar1) && !empty($bar2) && !empty($bar3)){ ?>
$.jqplot('chart1', [bar1, bar2, bar3], optionsObj);
<?php } else if(!empty($bar1) && !empty($bar2)){ ?>
$.jqplot('chart1', [bar1, bar2], optionsObj);
<?php } else if(!empty($bar2) && !empty($bar3)){ ?>
$.jqplot('chart1', [bar2, bar3], optionsObj);
<?php } else if(!empty($bar1) && !empty($bar3)){ ?>
$.jqplot('chart1', [bar1, bar3], optionsObj);
<?php } else if(!empty($bar1)){ ?>
$.jqplot('chart1', [bar1], optionsObj);
<?php } else if(!empty($bar2)){ ?>
$.jqplot('chart1', [bar2], optionsObj);
<?php } else if(!empty($bar3)){ ?>
$.jqplot('chart1', [bar3], optionsObj);
<?php } ?>
});