我正在尝试将明细图表集成为明智的购买数量。在单击栏时,要显示带有金额的机构详细信息。
第一部分显示完美。同时点击正确的栏。 显示标签(即机构名称),但数据值不起作用。同时提供静态数据可以正常工作。我生成并通过该栏的相同方式未显示。下面是我的PHP代码。
foreach($prw as $value){
$data['productid']=$value->productid;
$qry=$this->Crm_model->getProductSubscribedDetails($data);
$drillval="";
$insname="";
$datadrill[$value->productshortname]="";
$labeldrill[$value->productshortname]="";
foreach($qry as $drilval){
$drillval.=$drilval->amountafterreduction.",";
$insname.="'".$drilval->sub_ins_name."',";
}
$drillval1=rtrim($drillval,",");
$insname1=rtrim($insname,",");
$datadrill[$value->productshortname]=$drillval1;
$labeldrill[$value->productshortname]=$insname1;
$drillval1="";
$insname1="";
$pname.="'".$value->productshortname."',";
$curyrtotal=$value->total;
$state=$value->state_name;
if($curyrtotal==""){
$curyrtotal[$value->productid]=0;}
$label.=$curyrtotal.",";
}
//print_r($labeldrill);
$ldr=$labeldrill;//print_r($ldr);
$labeljson = json_encode($ldr);
$datajson=json_encode($datadrill);
//echo count($datadrill);
$label1=rtrim($label,",");
$name2=rtrim($name1,",");
?>
我有datajson值
{"JFET":"2700,2325,2700,2700,7300,2700,2700,2700,2325,2700,2325,
1204,2700,2100,2700,2700,2700,2700,800,2700,2200,2700,800,800,800,
800,
2325,2700,2325,2325,2700,0","JSE":"2325,7300,7300,2700,2700,2700,2700,
2700,
2700,2700,2325,2700,2700,2700,2325,2700,2700,2700,2100,2700,2700,2700,
2700,
2700,2700,2700,2200,800,2700,2700,2700,2700,2200,2700,800,2700,800,800,
2325,
2700,2700,2700,2325,2325,2700,2700"}
对于2种产品。
下面是我的jQuery
<script>
window.onload = function ()
{
var objarr = <?php echo json_encode($datajson); ?>; //alert(objarr)
var myJSON = JSON.parse(objarr);//alert(myJSON[JFET])
var objarrlabel = <?php echo json_encode($labeljson); ?>;
var myJSONlabel = JSON.parse(objarrlabel);
var ca = document.getElementById("cvs"); //alert(ca)
var data = [<?=$label1?>]; //alert(data.length)
var data_drilldown = [];
var d1 = [];
var labels1 = [<?=$name2?>]
// var d="$datadrill";
/**
* The drilldown data - the order corresponds to that of the labels
*/
var word,v;
for(var k=0; k<data.length; ++k){
var l=labels1[k];
var m=myJSON[l];//alert(m)
var words = m.split(',');
var len=words.length;
for(var m1=0;m1<len;m1++){
//word+=words[words]+","
d1.push(words[m1]);
}
data_drilldown.push(d1);
d1=[];
}
var labels = [<?=$name2?>]
/* data_drilldown.push([2,3,1,2,3,1,3]);
data_drilldown.push([2,2,2,1,2,2,3]);
data_drilldown.push([1,1,1,2,3,2,2]);
data_drilldown.push([3,3,3,2,3,3,1]);
data_drilldown.push([4,3,1,1,3,2,2]);
data_drilldown.push([3,2,2,2,3,1,0]);*/
var bar = drawMainChart();
/**
* Draws the main chart
*/
function drawMainChart ()
{// var ca = document.getElementById("cvs");
RGraph.reset(ca);
var bar = new RGraph.Bar({
id: 'cvs',
data: data,
options: {
labels: labels,
bevel: !RGraph.ISOLD,
title: 'The whole teams statistics for sales of widgets',
backgroundGridAutofitNumvlines: data.length,
strokestyle:'rgba(0,0,0,0)',
textAccessible: true,
shadow: true,
textColor: '#666',
textSize: 10,
}
}).fadeIn();
/**
* When a bar is clicked show a more detailed breakdown
*/
bar.onclick = function (e, shape)
{
// var canvas = document.getElementById("cvs");
// if(canvas.getContext) {
//var context = canvas.getContext("2d");
var obj = e.target.__object__;
var ca = obj.canvas;//alert(ca)
var idx = shape.index;
//alert(d1[idx]);
alert(data_drilldown[idx]);
alert(data_drilldown[idx].length);
//var dd=[data_drilldown[idx]]; alert(dd)
//alert([myJSON[labels[idx]]])
// alert(myJSONlabel[labels[idx]])
/**
* Slide the old bar out
*/
obj.fadeOut(null, function ()
{
RGraph.reset(ca);
var bar = new RGraph.Bar({
id: 'cvs',
data: data_drilldown[idx],
//data:[myJSON[labels[idx]]],
options: {
labels: [myJSONlabel[labels[idx]]],
bevel: true,
strokestyle: 'rgba(0,0,0,0)',
title: 'Specific statistics for: ' + labels[idx],
backgroundGridAutofitNumvlines: data.length,
textAccessible: true,
ylabelsCount:10,
textColor: '#666',
textSize: 10,
gutterLeft: 75,
yaxisLabelsValign:20,
}
}).fadeIn();
});
//}
}
/**
* The onmousemove event to change the cursor
*/
bar.onmousemove = function (e, shape)
{
return true;
}
return bar;
}
document.getElementById("butBack").onclick = function (e)
{
var obj = ca.__object__;
obj.fadeOut(null,function ()
{
var bar = drawMainChart();
});
}
};
</script>
在alert(data_drilldown[idx]);
期间,我有所收获,但在错误控制台中未显示任何错误。我认为转换json数组或字符串可能有问题。