PHP Generate pie chart, line chart, bar chart General Class 2

Source: Internet
Author: User
Tags php class

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.