php 統計每天價格,貨幣種類,匯總得演算法和資料處理 (後端和前段實現自動統計價格和幣種類型)

來源:互聯網
上載者:User

標籤:his   search   sea   演算法   font   sed   nts   count   jquer   

    //30天收入走勢圖    public function actionIncome()    {       /* $l sql查詢後資料結構(分組日期和幣種)       array[0=>array[           ‘date‘ => ‘20180208‘,---日期           ‘fee‘ => ‘10.00‘,    ---價格           ‘currency‘ => ‘USD‘, ---幣種類型       ],1=>array[           ‘date‘ => ‘20180208‘,           ‘fee‘ => ‘20.00‘,           ‘currency‘ => ‘TWD‘,       ]];*/        $l = $this->incomeService->getDateIncomeList();        /* $type sql查詢後資料結構(distinct幣種欄位)        array[0=>array[            ‘currency‘ => ‘USD‘,         ],1=>array[            ‘currency‘ => ‘TWD‘,        ]];*/        $type = $this->incomeService->getCurrency();        $number = count($type);        /* $data_type 幣種類型,資料處理過後結構        array[            0 => ‘USD‘,            1 => ‘TWD‘,        ];*/        $data_type = array();        foreach ($type as $key=>$value) {            $data_type[$key] = $value[‘currency‘];        }        /* $data_total 統計每天不同幣種價格,資料處理過後結構        array[‘USD‘=>array[            ‘20180208‘ => ‘10.00‘,            ‘20180207‘ => ‘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 統計30天幣種匯總,資料處理過後結構        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 統計時間,資料處理過後結構        array[‘20180208‘=>array[            ‘date‘ => ‘20180208‘,        ],‘20180207‘=>array[            ‘date‘ => ‘20180207‘,        ]];*/        $time = array();        foreach ($l as $key=>$value) {            $time[$value[‘date‘]][‘date‘] = $value[‘date‘];        }        /* $list 匯總合并每天不同幣種,資料處理過後結構        array[‘20180208‘=>array[            ‘date‘ => ‘20180208‘,            ‘USD‘ => ‘10.00‘,            ‘TWD‘ => ‘20.00‘,        ],‘20180207‘=>array[            ‘date‘ => ‘20180207‘,            ‘USD‘ => ‘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資料圖表外掛程式資料處理 ---(可以用百度等外掛程式)        $chartsData = $this->searchChartsDataFormat($list);        $this->render(‘income‘, array(            ‘list‘ => $list,            ‘chartsData‘ => $chartsData,            ‘total_sum‘ => $total_sum,            ‘number‘ => $number,            ‘data_type‘ => $data_type,        ));    }    /**     * [searchChartsData 資料圖表使用]     * @param  string $sql [description]     * @return [type]      [array]     */    public function searchChartsDataFormat($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;    }
//前端資料處理和後端資料處理邏輯相似
<div id="incomeChat" style="width: 90%;height:50px;"></div><div> <div id="container" style="min-width:400px;height:400px"></div></div><div class="table-responsive"> <table class="table table-bordered table-condensed"> <thead> <tr class="xmsb-admin-table-head"> <th>日期</th> <?php for($i=0; $i<$number; $i++){?> <th><?php echo $data_type[$i]; ?></th> <?php }?> </tr> </thead> <tbody> <?php foreach($list as $lv){?> <tr> <td><?php echo $lv[‘date‘]; ?></td> <?php for($i=0; $i<$number; $i++){?> <td><?php echo $lv[$data_type[$i]]; ?></td> <?php }?> </tr> <?php }?> <tr class="xmsb-admin-table-head"> <td>匯總</td> <?php for($i=0; $i<$number; $i++){?> <td><font size="2" color="red"><?php echo $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"> var chart = new Highcharts.Chart(‘container‘, { title: { text: ‘‘,x: -20 }, subtitle: { text: ‘‘, x: -20 }, xAxis: { categories: [<?php echo isset($chartsData[‘date‘])?$chartsData[‘date‘]:‘‘; ?>] }, yAxis: { title: { text: ‘30天價格統計‘ }, plotLines: [{ value: 0, width: 1, color: ‘#808080‘ }] }, tooltip: { valueSuffix: ‘‘ }, legend: { layout: ‘vertical‘, align: ‘right‘, verticalAlign: ‘middle‘, borderWidth: 0 }, series: [{ name: ‘CNY‘, data: [<?php echo isset($chartsData[‘total_CNY‘])?$chartsData[‘total_CNY‘]:""; ?>] },{ name: ‘THB‘, data: [<?php echo isset($chartsData[‘total_THB‘])?$chartsData[‘total_THB‘]:""; ?>] }, { name: ‘TWD‘, data: [<?php echo isset($chartsData[‘total_TWD‘])?$chartsData[‘total_TWD‘]:""; ?>] }, { name: ‘USD‘, data: [<?php echo isset($chartsData[‘total_USD‘])?$chartsData[‘total_USD‘]:‘‘; ?>] }] });</script>

 上面代碼實現功能

php 統計每天價格,貨幣種類,匯總得演算法和資料處理 (後端和前段實現自動統計價格和幣種類型)

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.