在php中施用FusionCharts
在php中使用FusionCharts
作者:zccst
数据格式有setDataURL(srcUrl)和setJSONData(jsonStr)两种
用法在官方demo和document都有详细解释。
在实际需求中,直接参考官方资料还是挺方便的。
fileUrl = '../path/to/xx.swf'; //swf文件路径
srcUrl = 'http://url?a=1&b=2'; //向后端请求的url。
一、setDataURL(srcUrl)方式
//前端: <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;
批注1:本质是data.xml,可以直接丢一个data.xml格式的文件,也可以是一个url,该url的返回值是xml格式的数据。
批注2:有可能乱码。在yii中使用会乱码。但在extjs中没有。
二、setJSONData(jsonStr)
又分两种情况:
第一种情况是new FusionCharts(...)在前端,仅jsonStr从后端获取
例如:
//前端: <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);
批注:$.post()的返回值是'json'类型。
第二种情况是所有都在后端,前端直接$(".outsource_content").html(r)
//前端: <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; }
批注1:$.post()的返回值是'html'类型。也可以测试其他类型是否可以正常显示。
但是不能是json格式。其本质是一些已经组建好的javascript,添加到制定div后就立即执行了。
批注2:针对第二种情况,也可以显示两个图表,(当然也可以显示多个)
后端在添加:
$ret2 = $ret; $ret2 = self::generateChart('Column2D', $ret2, 600,500,'myid2','outsource_sta_2'); $ret2 = self::wrapScript($ret2); print $ret.$ret2;
三、setJSONData()的高级形式
高级的原因是:后端不只是传来渲染图表(fusionCharts)的完整js,还包括其他值,此时$.post()的返回值是'json'类型。
//前端: $.post(srcUrl,null,function(r){ console.log(r.v); $(".outsource_content").html(r.g); },'json'); //后端: //在上面的基础上 $return = array('v'=>100,'g'=>$ret.$ret2);
批注1:100的位置可以放置任意负责的数据,而且还可以v1,v2等等。
批注2:此时$.post()的返回值是'json'类型。这个必须强调。

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

Many users will choose the Huawei brand when choosing smart watches. Among them, Huawei GT3pro and GT4 are very popular choices. Many users are curious about the difference between Huawei GT3pro and GT4. Let’s introduce the two to you. . What are the differences between Huawei GT3pro and GT4? 1. Appearance GT4: 46mm and 41mm, the material is glass mirror + stainless steel body + high-resolution fiber back shell. GT3pro: 46.6mm and 42.9mm, the material is sapphire glass + titanium body/ceramic body + ceramic back shell 2. Healthy GT4: Using the latest Huawei Truseen5.5+ algorithm, the results will be more accurate. GT3pro: Added ECG electrocardiogram and blood vessel and safety

Why Snipping Tool Not Working on Windows 11 Understanding the root cause of the problem can help find the right solution. Here are the top reasons why the Snipping Tool might not be working properly: Focus Assistant is On: This prevents the Snipping Tool from opening. Corrupted application: If the snipping tool crashes on launch, it might be corrupted. Outdated graphics drivers: Incompatible drivers may interfere with the snipping tool. Interference from other applications: Other running applications may conflict with the Snipping Tool. Certificate has expired: An error during the upgrade process may cause this issu simple solution. These are suitable for most users and do not require any special technical knowledge. 1. Update Windows and Microsoft Store apps

Part 1: Initial Troubleshooting Steps Checking Apple’s System Status: Before delving into complex solutions, let’s start with the basics. The problem may not lie with your device; Apple's servers may be down. Visit Apple's System Status page to see if the AppStore is working properly. If there's a problem, all you can do is wait for Apple to fix it. Check your internet connection: Make sure you have a stable internet connection as the "Unable to connect to AppStore" issue can sometimes be attributed to a poor connection. Try switching between Wi-Fi and mobile data or resetting network settings (General > Reset > Reset Network Settings > Settings). Update your iOS version:

php提交表单通过后,弹出的对话框怎样在当前页弹出php提交表单通过后,弹出的对话框怎样在当前页弹出而不是在空白页弹出?想实现这样的效果:而不是空白页弹出:------解决方案--------------------如果你的验证用PHP在后端,那么就用Ajax;仅供参考:HTML code

The data folder contains system and program data, such as software settings and installation packages. Each folder in the Data folder represents a different type of data storage folder, regardless of whether the Data file refers to the file name Data or the extension. Named data, they are all data files customized by the system or program. Data is a backup file for data storage. Generally, it can be opened with meidaplayer, notepad or word.

Watch4pro and gt each have different features and applicable scenarios. If you focus on comprehensive functions, high performance and stylish appearance, and are willing to bear a higher price, then Watch 4 Pro may be more suitable. If you don’t have high functional requirements and pay more attention to battery life and reasonable price, then the GT series may be more suitable. The final choice should be decided based on personal needs, budget and preferences. It is recommended to carefully consider your own needs before purchasing and refer to the reviews and comparisons of various products to make a more informed choice.

The solution to the garbled mysql load data: 1. Find the SQL statement with garbled characters; 2. Modify the statement to "LOAD DATA LOCAL INFILE "employee.txt" INTO TABLE EMPLOYEE character set utf8;".

How to Optimize iPad Battery Life with iPadOS 17.4 Extending battery life is key to the mobile device experience, and the iPad is a good example. If you feel like your iPad's battery is draining too quickly, don't worry, there are a number of tricks and tweaks in iPadOS 17.4 that can significantly extend the run time of your device. The goal of this in-depth guide is not just to provide information, but to change the way you use your iPad, enhance your overall battery management, and ensure you can rely on your device for longer without having to charge it. By adopting the practices outlined here, you take a step toward more efficient and mindful use of technology that is tailored to your individual needs and usage patterns. Identify major energy consumers
