//30 daysIncome Trend Chart Public functionActionincome () {/*$l SQL query data structure (packet date and currency) array[0=>array[' date ' = ' 20180208 ',---date ' fee ' + ' 10.00 ' ,---price ' currency ' + ' USD ',---currency type],1=>array[' date ' = ' 20180208 ', ' FE E ' = ' 20.00 ', ' currency ' = ' TWD ',];*/ $l=$this->incomeservice->getdateincomelist (); /*$type SQL query data structure (distinct currency field) array[0=>array[' currency ' + ' USD ',],1=>array[ ' Currency ' = ' TWD ',];*/ $type=$this->incomeservice->getcurrency (); $number=Count($type); /*$data _type currency type, after data processing structure array[0 = ' USD ', 1 = ' TWD ',];*/ $data _type=Array(); foreach($type as $key=$value) { $data _type[$key] =$value[' Currency ']; } /*$data _total statistics daily different currency price, data processing structure array[' USD ' =>array[' 20180208 ' + ' 10.00 ', ' 201802 "= ' = ' 20.00 ',], ' TWD ' =>array[' 20180208 ' = ' 10.00 ', ' 20180207 ' = ' 20.00 ',, ]];*/ $data _total=Array(); foreach($l as $key=$value) { $data _total[$value[' Currency '] [$value[' Date '] =$value[' Fee ']; } /*$total _sum Statistics 30 days currency Summary, data processing structure array[' USD ' = ' 10.00 ', ' TWD ' = ' 20.00 ',];
*/ $total _sum=Array(); for($i= 0;$i<$number;$i++){ $total _sum[$data _type[$i]] =Empty($data _total[$data _type[$i]]) ? 0:Array_sum($data _total[$data _type[$i]]); } /*$time statistical time, after data processing structure array[' 20180208 ' =>array[' date ' = ' 20180208 ',], ' 20180207 ' =>ar ray[' Date ' = ' 20180207 ',];*/ $time=Array(); foreach($l as $key=$value) { $time[$value[' Date '] [' Date '] =$value[' Date ']; } /*$list Summary Merge daily different currencies, data processing after structure array[' 20180208 ' =>array[' date ' = ' 20180208 ', ' USD ' =&G T ' 10.00 ', ' TWD ' = ' 20.00 ',], ' 20180207 ' =>array[' date ' = ' 20180207 ', ' US D ' = ' 10.00 ', ' TWD ' = ' 20.00 ',];*/ $list=Array(); foreach($time as $key=$value){ $list[$key[' Date '] =$key; for($i= 0;$i<$number;$i++){ $list[$key][$data _type[$i]] =Empty($data _total[$data _type[$i]][$key]) ? 0:$data _total[$data _type[$i]][$key]; } } //highcharts Data Graph plug-in processing---(can use Baidu and other plug-ins) $chartsData=$this->searchchartsdataformat ($list); $this->render (' Income ',Array( ' List ' =$list, ' chartsdata ' =$chartsData, ' total_sum ' =$total _sum, ' number ' =$number, ' data_type ' =$data _type, )); } /** * [Searchchartsdata Data Chart Use] * @param string $sql [description] * @return [type] [array]*/ Public functionSearchchartsdataformat ($data){ if(!Is_array($data))return Array(); $day=$total _CNY=$total _THB=$total _TWD=$total _USD=Array(); $result=Array(); foreach($data as $k=$v) { $day[]= '].$v[' Date ']. ' \‘‘; $total _CNY[]=$v[' CNY ']; $total _THB[]=$v[' THB ']; $total _TWD[]=$v[' TWD ']; $total _USD[]=$v[' USD ']; } $result[' Date ']=implode(‘,‘,Array_reverse($day) ); $result[' Total_cny ']=implode(‘,‘,Array_reverse($total _CNY) ); $result[' TOTAL_THB ']=implode(‘,‘,Array_reverse($total _THB) ); $result[' TOTAL_TWD ']=implode(‘,‘,Array_reverse($total _TWD) ); $result[' TOTAL_USD ']=implode(‘,‘,Array_reverse($total _USD) ); return $result; }
Front-end data processing and back-end data processing logic similar
<div id= "Incomechat" style= "width:90%;height:50px;" ></div><div> <div id= "container" style= "min-width:400px;height:400px" ></div></div ><divclass= "Table-responsive" > <tableclass= "Table table-bordered table-condensed" > <thead> <trclass= "Xmsb-admin-table-head" > <th> date </th> <?php for($i= 0;$i<$number;$i+ +) {?> <th><?phpEcho $data _type[$i];?></th> <?php}?> </tr> </thead> <tbody> <?p Hpforeach($list as $LV) {?> <tr> <td><?phpEcho $LV[' Date '];?></td> <?php for($i= 0;$i<$number;$i+ +) {?> <td><?phpEcho $LV[$data _type[$i]];?></td> <?php}?> </tr> <?php}?> <trclass= "Xmsb-admin-table-head" > <td> summary </td> <?php for($i= 0;$i<$number;$i+ +) {?> <td><font size= "2" color= "Red" ><?phpEcho $total _sum[$data _type[$i]];?></font></td> <?php}?> </tr> </tbody> </table>< ;/div><!--jQuery--><script src= "/public/bower_components/jquery/dist/jquery.min.js" ></script ><script type= "Text/javascript" src= '/public/js/highcharts.js ' ></script><script type= "text/ JavaScript "src= '/public/js/highcharts-zh_cn.js ' ></script><script type=" Text/javascript ">varChart =NewHighcharts.chart (' Container ',{title: {text: ', x:-20},subtitle: {text: ', x:-20},Xaxis:{Categories: [<?phpEcho isset($chartsData[' Date ']?$chartsData[' Date ']: ';?>] },YAxis:{title: {text: ' 30 Day Price Statistics '},Plotlines: [{value:0, width:1, color: ' #808080 ' }] },tooltip:{Valuesuffix: ‘‘ },legend:{Layout: ' Vertical ', align: ' right ', verticalalign: ' Middle ', borderwidth:0 },Series:[{Name: ' CNY ',Data: [<?phpEcho isset($chartsData[' TOTAL_CNY '])?$chartsData[' Total_cny ']: "";?>] },{Name: ' THB ',Data: [<?phpEcho isset($chartsData[' TOTAL_THB '])?$chartsData[' TOTAL_THB ']: "";?>] },{Name: ' TWD ',Data: [<?phpEcho isset($chartsData[' TOTAL_TWD '])?$chartsData[' TOTAL_TWD ']: "";?>] },{Name: ' USD ',Data: [<?phpEcho isset($chartsData[' TOTAL_USD '])?$chartsData[' TOTAL_USD ']: ';?>] }] });</script>
The above code implements the function
PHP statistics daily price, currency category, aggregated algorithm and data processing (back end and front segment implementation Auto-statistic price and currency type)