Yii2中的Highchart基本列

时间:2018-07-18 03:37:53

标签: php highcharts yii2

我想使用带有Yii2的图表来创建图表,该数据是希望每年按月显示的雇员离职信息。

在这里,我使用postgresql,并创建如下查询:

['LukeSkywalker', 'HanSolo']

结果:

 mon |           name           | total
-----+--------------------------+-------
 Aug | ALEX NOERDIN             |     1
 Jul | ALEX NOERDIN             |     1
 Jul | ANNA MARRIAM             |     2
 

如何在postgresql上按月显示其值为空的数据。 我想要这样的查询结果:


  mon |           name           | total
-----+--------------------------+-------
 Jan | ALEX NOERDIN             |     0
 Jan | ANNA MARRIAM             |     0
 Feb | ALEX NOERDIN             |     0
 Feb | ANNA MARRIAM             |     1
 Mar | ALEX NOERDIN             |     1
 Mar | ANNA MARRIAM             |     0
 Apr | ALEX NOERDIN             |     1
 Apr | ANNA MARRIAM             |     0
 Mei | ALEX NOERDIN             |     1
 Mei | ANNA MARRIAM             |     2 
 Jun | ALEX NOERDIN             |     2
 Jun | ANNA MARRIAM             |     1
 Jul | ALEX NOERDIN             |     0
 Jul | ANNA MARRIAM             |     0
 Aug | ALEX NOERDIN             |     0
 Aug | ANNA MARRIAM             |     0
 Sep | ALEX NOERDIN             |     0
 Sep | ANNA MARRIAM             |     0
 Okt | ALEX NOERDIN             |     0
 Okt | ANNA MARRIAM             |     0
 Nov | ALEX NOERDIN             |     0
 Nov | ANNA MARRIAM             |     0
 Dec | ALEX NOERDIN             |     0
 Dec | ANNA MARRIAM             |     0 

我正在尝试使用Yii2和highchart小部件创建图表 首先,我创建一个函数以从Model中的数据库查询结果中检索数据

型号:

workleavedb=# SELECT to_char(start_date,'Mon') AS mon,employee.name,count(workleave.id) AS total FROM workleave INNER JOIN employee ON
 workleave.employee_id = employee.id WHERE start_date >= '2018-01-01' AND start_date <= '2018-12-31'  GROUP BY 1,2;

控制器:

public static function getGraph(){
    $sql = "select to_char(start_date,'Mon') as bln,pegawai.nama,count(cuti.id) as total from cuti inner join pegawai on cuti.pegawai_id = pegawai.id group by 1,2";
    $result = Yii::$app->db->createCommand($sql)->queryAll();
    return $result;
}   

查看:

public function actionGraphic()
{
   $data = Report::getGraph();
   return $this->render('graphic', [
   'dgrafik' => $data
   ]);
}

但是图形显示与我想要的不匹配。查询结果的图形如下所示: Result 我想创建一个这样的图 My Expectations Chart

0 个答案:

没有答案