yii2开发笔记---- echart折线图表

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/weixin_41120504/article/details/82113832

使用composer 下载插件

在命令行 进入到项目根目录下输入composer require "hisune/echarts-php"进行下载

在视图打印一下控制器传过来的值来确定你所需要的数据

控制器:

然后在视图加上折线图表的代码(根据自己所需的数据来调整)

?<php
use Hisune\EchartsPHP\ECharts;
?>
<div id="chart1">
        <?php  //print_r($models);exit;//打印控制器传来的值
        foreach ($models as $key => $res) {
            $time[] = $res['time'];
            $gold_income[] = $res['gold_income'];
            $gold_expenditure[] = $res['gold_expenditure'];
            $totalGold[] = $res['totalGold'];
        }
        $chart = new ECharts();
        $chart->title->text = '财富数据统计';
        $chart->title->left= 'center';
        $chart->title->top= '-6px';
        $chart->tooltip->show = true;
        $chart->legend->data[] = '收入';
        $chart->legend->data[] = '支出';
        $chart->legend->data[] = '总和';
        $chart->legend->top= '25px';
        $chart->xAxis[] = array(
            'type' => 'category',
            'data' => $time
        );
        $chart->yAxis[] = array(
            'type' => 'value'
        );


        $chart->series[] = array(
            'name' => '收入',
            'type' => 'line',
            'stack' => '总量',
            'data' => $gold_income

        );
        $chart->series[] = array(
            'name' => '支出',
            'type' => 'line',
            'stack' => '总量',
            'data' => $gold_expenditure

        );
        $chart->series[] = array(
            'name' => '总和',
            'type' => 'line',
            'stack' => '总量',
            'data' => $totalGold

        );
        echo $chart->render('simple-custom-1');

        ?>
    </div>

猜你喜欢

转载自blog.csdn.net/weixin_41120504/article/details/82113832
今日推荐