Generate pie chart, line chart, bar chart general PHP class, here is the use of foreign highcharts, front page Don't forget to call Highcahrt JS
Highcharts Chinese website http://www.hcharts.cn/index.php
<?PHP/** * Created by Phpstorm. * User:wang * DATE:2015/7/26 * time:11:19*/namespace Org\wechat;classhighcharts{/** * Get the report of JS generated chart * @param $id dom element ID * @param array $data chart data * @param $type chart Type Line chart: line Pie chart: Pie bar chart: Column * @param string $title Chart main Title * @param string $subtitle subtitle * @return string*/ Public functionGethighcharts ($id,Array $data,$type,$title= ",$subtitle= ",$yTitle= ' ') { $series= ' '; if(Empty($data)) { $data=Array( ' Categories ' =Array( ' Data ' =Array(‘-‘) ), ' xaxis ' =Array( ' Type ' = ' category ', ' boundarygap ' = ' false ', ' data ' =Array(‘‘) ), ' series ' =Array( Array( ' Name ' = '-', ' type ' = ' line ', ' itemstyle ' = ' = ' {normal: {areastyl E: {type: ' Default '}} ', ' data ' =Array() ), ) ); } foreach($data as $key=$value) { Switch($key) { Case' Categories ':$categories= ' ['; foreach($value as $k=$v) { //categories: [' Jan ', ' Feb ', ' Mar ', ' Apr ', ' may ', ' June ', ' Jul ', ' April ', ' Sep ', ' Oct ', ' Nov ', ' Dec '] $categories=$categories. Json_encode ($v, Json_unescaped_unicode). ‘,‘; } $categories=$categories. ‘]‘; Break; Case' Xaxis ':foreach($value as $k=$v) { Switch($k) { Case' Type ':$xaxis[] =$k. ":‘" .$v. "‘"; Break; Case' Data ':$xaxis[] =$k. ‘:‘ . Json_encode ($v,Json_unescaped_unicode); Break; } } $xaxis= ' {'.implode(‘, ‘,$xaxis) . ‘}‘; Break; //{name: ' Tokyo ', data: [7.0, 6.9, 9.5, 14.5, 18.2, 21.5, 25.2, 26.5, 23.3, 18.3, 13.9, 9.6]} Case' Series ':foreach($value as $list) { $tmp=Array(); foreach($list as $k=$v) { Switch($k) { Case' Name ': Case' Type ':$tmp[] =$k. ":‘" .$v. "‘"; Break; Case' ItemStyle ':$tmp[] =$k. ‘:‘ .$v; Break; Case' Data ':$tmp[] =$k. ‘:‘ . Json_encode ($v,Json_unescaped_unicode); } } $series[] = ' {'.implode(‘, ‘,$tmp) . ‘}‘; } $series=implode(‘, ‘,$series); Break; } } if($type!== ' Pie ') { $str= "Xaxis:{categories:$categories},"; } Else { $str= ' '; } $script= <<<EOT<script type= "Text/javascript" > $(function () { $(' # $id ').Highcharts ({title:{text: ' $title ',x:-20//Center},subtitle:{text: ' $subtitle ',x:-20 },credits:{enabled:false },$strYAxis:{title:{text: ' $yTitle ' },Plotlines:[{Value: 0,width: 1,Color: ' #808080 ' }] },tooltip:{Valuesuffix: ‘%‘ },legend:{Layout: ' Vertical ',Align: ' Right ',verticalalign: ' Middle ',BorderWidth: 0 },Series: [$series] });});</script>EOT; return $script; }}
PHP Generate pie chart, line chart, bar chart General Class 2