日期:2014-05-17 浏览次数:25494 次
//前端: <div id="outsource_sta_1"></div> var myChart = new FusionCharts(fileUrl, "myChartId", "600", "500"); myChart.setDataURL(srcUrl); myChart.render("outsource_sta_1"); //后端: $xml = "<chart palette=\"2\" caption=\"平均处理时间统计\" xAxisName=\"机型\" yAxisName=\"平均处理时间\" showValues=\"1\" decimals=\"2\" formatNumberScale=\"0\" useRoundEdges=\"1\" showPercentValues='1' >"; for($i = 1; $i < 6; $i++){ $data[] = array('label'=>'m'.$i, 'value'=>$i); $xml .= "<set label=\"'m'.$i\" value=\"$i\" />"; } $xml .= "</chart>"; print $xml;
//前端: <div id="outsource_sta_1"></div> $.post(srcUrl,null,function(r){ var myChart = new FusionCharts(fileUrl, "myChartId", "600", "500"); myChart.setJSONData(r); myChart.render("outsource_sta_1"); },'json'); //后端: $data = array(); for($i = 1; $i < 6; $i++){ $data[] = array('label'=>'m'.$i, 'value'=>$i); } $chart = array(); $chart['palette'] = 2; $chart['caption'] = "平均处理时间统计"; $chart['xAxisName'] = "机型"; $chart['yAxisName'] = "平均处理时间"; $chart['showValues'] = 1; $chart['decimals'] = 2; $chart['formatNumberScale'] = 0; $chart['useRoundEdges'] = 1; $chart['showPercentValues'] = 1; $ret = array('chart'=>$chart,'data'=>$data); print json_encode($ret);
//前端: <div id="outsource_sta_1"></div> $.post(srcUrl,null,function(r){ $(".outsource_content").html(r); },'html'); //后端: $data = array(); for($i = 1; $i < 6; $i++){ $data[] = array('label'=>'m'.$i, 'value'=>$i); } $chart = array(); $chart['palette'] = 2; $chart['caption'] = "平均处理时间统计"; $chart['xAxisName'] = "机型"; $chart['yAxisName'] = "平均处理时间"; $chart['showValues'] = 1; $chart['decimals'] = 2; $chart['formatNumberScale'] = 0; $chart['useRoundEdges'] = 1; $chart['showPercentValues'] = 1; $ret = array('chart'=>$chart,'data'=>$data); $ret = json_encode($ret); $ret = self::generateChart('Column2D',$ret, 600,500, 'myid1', 'outsource_sta_1'); $ret = self::wrapScript($ret); print $ret; public static function wrapScript($scripts){ $html = '<script type="text/javascript">'; $html.= "\n"; $html.= $scripts; $html.= "\n"; $html.= "</script>"; return $html; } public static function generateChart($type, $data, $width=0, $height=0, $myid='', $div_id=''){ if(!$type || !$data){ return ''; } $width = intval($width)?intval($width):800; $height = intval($height)?intval($height):400; $width = $width<600?600:$width; $height = $height<400?400:$height; $url = Yii::app()->baseUrl . "/resources/fusion/{$type}.swf"; $mychartid = $myid . 'a'; $script = <<<JAVASCRIPT var {$myid} = new FusionCharts('{$url}','{$mychartid}', '{$width}','{$height}'); {$myid}.setJSONData('{$data}'); {$myid}.render('{$div_id}'); JAVASCRIPT; return $script; }