url_renderer = "http://localhost:3030/chart"; } function render($type, $id) { switch ($type) { case "mcu001": $this->mcu001($id); break; case "mcu002": $this->mcu002($id); break; } } // --> MCU001 function mcu001($id) { // 1. prepare the data using sql $sql = "SELECT count(Mcu_OrderT_OrderHeaderID) as peserta,Mgm_McuTotalParticipant as total FROM mgm_mcu join mcu_order on Mcu_OrderMgm_McuID = Mgm_McuID where Mgm_McuID = ?"; $qry = $this->db->query($sql, [$id]); $this->check_error($qry, "get total mcu"); $rows = $qry->result_array(); if (count($rows) == 0) { $this->chart_error("No data found"); } $total = $rows[0]["total"]; $peserta = $rows[0]["peserta"]; $belum_mcu = $total - $peserta; // 2. generate parameter for the chart $param = array( 'title' => array( 'text' => 'Peserta MCU', 'subtext' => 'Total Peserta ' . $total, 'left' => 'center' ), 'tooltip' => array( 'trigger' => 'item' ), 'legend' => array( 'top' => 'bottom', 'left' => 'center', 'orient' => 'vertical' ), 'series' => array( array( 'label' => array( 'position' => 'inner', 'formatter' => '{d}%' ), 'name' => 'Access From', 'type' => 'pie', 'radius' => array('20%', '50%'), 'itemStyle' => array( 'borderRadius' => 10, 'borderColor' => '#fff', 'borderWidth' => 2 ), 'data' => array( array("value" => $peserta, "name" => "Sudah MCU : $peserta Peserta"), array("value" => $belum_mcu, "name" => "Belum MCU : $belum_mcu Peserta") ), 'emphasis' => array( 'itemStyle' => array( 'shadowBlur' => 10, 'shadowOffsetX' => 0, 'shadowColor' => 'rgba(0, 0, 0, 0.5)' ) ) ) ) ); // 3. encapsulate in config attribute and json encode $config = ["config" => $param]; $j_param = json_encode($config); header("Content-Type: image/png"); // 4. post to chart renderer echo $this->post($this->url_renderer, $j_param); } // --> MCU002 function mcu002($id) { // 1. prepare the data using sql $sql = "SELECT M_PatientGender, count(Mcu_OrderT_OrderHeaderID) as total from mcu_order join t_orderheader on Mcu_OrderT_OrderHeaderID = T_OrderHeaderID and T_OrderHeaderIsActive = 'Y' left join m_patient ON T_OrderHeaderM_PatientID = M_PatientID AND M_PatientIsActive = 'Y' where Mcu_OrderMgm_McuID = ? group by M_PatientGender"; $qry = $this->db->query($sql, [$id]); $this->check_error($qry, "get total mcu"); $rows = $qry->result_array(); if (count($rows) == 0) { $this->chart_error("No data found"); } // $total = $rows[0]["total"]; // $M_SexCode = $rows[0]["M_PatientGender"]; $PriaTotal = 0; $WanitaTotal = 0; if (count($rows) > 0) { foreach ($rows as $key => $vx) { if ($vx['M_PatientGender'] == "male") { $PriaTotal = $vx["total"]; } else { $WanitaTotal = $vx["total"]; } } } // 2. generate parameter for the chart $param = array( 'title' => array( 'text' => 'Kepesertaan MCU', 'subtext' => 'Berdasarkan Jenis Kelamin', 'left' => 'center' ), 'tooltip' => array( 'trigger' => 'item' ), 'legend' => array( 'top' => 'bottom', 'left' => 'center', 'orient' => 'vertical' ), 'series' => array( array( 'label' => array( 'position' => 'inner', 'formatter' => '{d}%' ), 'name' => 'Access From', 'type' => 'pie', 'radius' => array('20%', '50%'), 'itemStyle' => array( 'borderRadius' => 10, 'borderColor' => '#fff', 'borderWidth' => 2 ), 'data' => array( array("value" => $PriaTotal, "name" => "Laki-laki : $PriaTotal Peserta"), array("value" => $WanitaTotal, "name" => "Perempuan : $WanitaTotal Peserta") ), 'emphasis' => array( 'itemStyle' => array( 'shadowBlur' => 10, 'shadowOffsetX' => 0, 'shadowColor' => 'rgba(0, 0, 0, 0.5)' ) ) ) ) ); // 3. encapsulate in config attribute and json encode $config = ["config" => $param]; $j_param = json_encode($config); header("Content-Type: image/png"); // 4. post to chart renderer echo $this->post($this->url_renderer, $j_param); } // --> MCU003 function mcu003($id) { // 1. prepare the data using sql $sql = 'SELECT CASE WHEN LEFT(T_OrderHeaderM_PatientAge, 2) < "30" THEN "1. < 30 tahun" WHEN LEFT(T_OrderHeaderM_PatientAge, 2) >= "30" AND LEFT(T_OrderHeaderM_PatientAge, 2) < "40" THEN "2. 30 -< 40 tahun" WHEN LEFT(T_OrderHeaderM_PatientAge, 2) >= "40" AND LEFT(T_OrderHeaderM_PatientAge, 2) < "50" THEN "3. 40 - < 50 tahun" WHEN LEFT(T_OrderHeaderM_PatientAge, 2) >= "50" THEN "4. > 50 tahun" ELSE "" END AS umur, COUNT(Mcu_OrderT_OrderHeaderID) AS total FROM mcu_order JOIN t_orderheader ON Mcu_OrderT_OrderHeaderID = T_OrderHeaderID AND T_OrderHeaderIsActive = "Y" LEFT JOIN m_patient ON T_OrderHeaderM_PatientID = M_PatientID AND M_PatientIsActive = "Y" WHERE Mcu_OrderMgm_McuID = ? GROUP BY CASE WHEN LEFT(T_OrderHeaderM_PatientAge, 2) < "30" THEN "1. < 30 tahun" WHEN LEFT(T_OrderHeaderM_PatientAge, 2) >= "30" AND LEFT(T_OrderHeaderM_PatientAge, 2) < "40" THEN "2. 30 -< 40 tahun" WHEN LEFT(T_OrderHeaderM_PatientAge, 2) >= "40" AND LEFT(T_OrderHeaderM_PatientAge, 2) < "50" THEN "3. 40 - < 50 tahun" WHEN LEFT(T_OrderHeaderM_PatientAge, 2) >= "50" THEN "4. > 50 tahun" ELSE "" END'; $qry = $this->db->query($sql, [$id]); $this->check_error($qry, "get total mcu"); $rows = $qry->result_array(); if (count($rows) == 0) { $this->chart_error("No data found"); } $data = []; if (count($rows) > 0) { foreach ($rows as $key => $vx) { $data[] = array( "value" => $vx["total"], "name" => $vx["umur"] . ":" . $vx['total'] . " Peserta" ); } } // 2. generate parameter for the chart $param = array( 'title' => array( 'text' => 'Peserta MCU', 'subtext' => 'Berdasarkan Umur', 'left' => 'center' ), 'tooltip' => array( 'trigger' => 'item' ), 'legend' => array( 'top' => 'bottom', 'left' => 'center', 'orient' => 'vertical' ), 'series' => array( array( 'label' => array( 'position' => 'inner', 'formatter' => '{d}%' ), 'name' => 'Access From', 'type' => 'pie', 'radius' => array('20%', '50%'), 'itemStyle' => array( 'borderRadius' => 10, 'borderColor' => '#fff', 'borderWidth' => 2 ), // 'data' => array( // array("value" => $rows[0]["total"], "name" => "< 30 Tahun : " . $rows[0]['total'] . " Peserta"), // array("value" => $rows[1]["total"], "name" => "30 - < 40 Tahun : " . $rows[1]['total'] . " Peserta"), // array("value" => $rows[2]["total"], "name" => "40 - < 50 Tahun : " . $rows[2]['total'] . " Peserta"), // array("value" => $rows[3]["total"], "name" => "≥ 50 Tahun : " . $rows[3]['total'] . " Peserta") // ), 'data' => $data, 'emphasis' => array( 'itemStyle' => array( 'shadowBlur' => 10, 'shadowOffsetX' => 0, 'shadowColor' => 'rgba(0, 0, 0, 0.5)' ) ) ) ) ); // 3. encapsulate in config attribute and json encode $config = ["config" => $param]; $j_param = json_encode($config); header("Content-Type: image/png"); // 4. post to chart renderer echo $this->post($this->url_renderer, $j_param); } // --> MCU004 function mcu004($id) { // 1. prepare the data using sql $sql = "SELECT ifnull(Nat_TestName ,Mcu_KelainanGroupName) as Test, count(Mgm_HeaderT_OrderHeaderID) as total FROM mgm_header join mgm_detail on Mgm_DetailMgm_HeaderID = Mgm_HeaderID and Mgm_DetailIsActive = 'Y' join mcu_kelainan on Mgm_DetailMcu_KelainanID = Mcu_KelainanID join mcu_kelainangroup on Mgm_DetailMcu_KelainanGroupID = Mcu_KelainanGroupID left join nat_test on Nat_TestCode = Mgm_HeaderNat_TestCode where Mgm_HeaderIsActive = 'Y' and Mgm_HeaderMgm_McuID = ? and Mgm_HeaderIsNormal = 'N' group by Mgm_DetailMcu_KelainanID ORDER BY count(Mgm_HeaderT_OrderHeaderID) DESC LIMIT 10"; $qry = $this->db->query($sql, [$id]); $this->check_error($qry, "get total mcu"); $rows = $qry->result_array(); if (count($rows) == 0) { $this->chart_error("No data found"); } // 2. generate parameter for the chart $color = [ 200, 150, 125, 100, 90, 80, 75, 70, 60, 50, ]; $param = array( 'title' => array( 'text' => 'Kelainan MCU', // 'subtext' => 'Living Expenses in Shenzhen' ), 'dataset' => array( 'source' => array( ['score', 'amount', 'product', 'percentage'], ), ), 'grid' => array( 'containLabel' => true ), 'xAxis' => array( 'name' => 'amount' ), 'yAxis' => array( 'type' => 'category' ), 'visualMap' => array( 'orient' => 'horizontal', 'left' => 'center', 'min' => 10, 'max' => 100, 'show' => false, 'dimension' => 0, 'inRange' => array( 'color' => array('#42aaf5', '#00eaf2', '#035bff') ) ), 'series' => array( array( 'label' => array( 'position' => 'right', 'show' => true, "formatter" => "{@[3]} %" // index ke 4 dari dataSource ), 'type' => 'bar', 'encode' => array( 'x' => 'amount', 'y' => 'product' ) ) ) ); if (count($rows) > 0) { $totalArray = array(); for ($i = 0; $i < count($rows); $i++) { if ($i < count($color)) { $totalArray[] = $rows[$i]['total']; } else { break; } } $maxTotal = max($totalArray); for ($i = 0; $i < count($rows); $i++) { if ($i < count($color)) { $percentage = (($rows[$i]['total'] / $maxTotal) * 100); $formattedPercentage = number_format($percentage, 2); $param['dataset']['source'][] = [ $color[$i], $rows[$i]['total'], $rows[$i]['Test'], $formattedPercentage ]; } else { break; } } } // 3. encapsulate in config attribute and json encode $config = ["config" => $param]; $j_param = json_encode($config); // echo $j_param; header("Content-Type: image/png"); // 4. post to chart renderer echo $this->post($this->url_renderer, $j_param); } // --> MCU005 function mcu005($id) { // 1. prepare the data using sql $sql = "SELECT Mcu_KelainanName, count(Mgm_HeaderT_OrderHeaderID) as total FROM mgm_header join mgm_detail on Mgm_DetailMgm_HeaderID = Mgm_HeaderID and Mgm_DetailIsActive = 'Y' join mcu_kelainan on Mgm_DetailMcu_KelainanID = Mcu_KelainanID join mcu_kelainangroup on Mgm_DetailMcu_KelainanGroupID = Mcu_KelainanGroupID where Mgm_HeaderIsActive = 'Y' and Mgm_HeaderMgm_McuID = ? and Mgm_HeaderType = 'F' and Mgm_HeaderIsNormal = 'N' group by Mcu_KelainanID ORDER BY count(Mgm_HeaderT_OrderHeaderID) DESC LIMIT 10"; $qry = $this->db->query($sql, [$id]); $this->check_error($qry, "get total mcu"); $rows = $qry->result_array(); if (count($rows) == 0) { $this->chart_error("No data found"); } // 2. generate parameter for the chart $color = [ 200, 150, 133, 125, 100, 80, 70, 60, 55, ]; $param = array( 'title' => array( 'text' => 'Kelainan Fisik', // 'subtext' => 'Living Expenses in Shenzhen' ), 'dataset' => array( 'source' => array( ['score', 'amount', 'product', 'percentage'], ), ), 'grid' => array( 'containLabel' => true ), 'xAxis' => array( 'name' => 'amount' ), 'yAxis' => array( 'type' => 'category' ), 'visualMap' => array( 'orient' => 'horizontal', 'left' => 'center', 'min' => 10, 'max' => 100, 'show' => false, // 'text' => array('High Score', 'Low Score'), 'dimension' => 0, 'inRange' => array( 'color' => array('#42aaf5', '#00eaf2', '#035bff') ) ), 'series' => array( array( 'label' => array( 'position' => 'right', 'show' => true, "formatter" => "{@[3]} %" // index ke 4 dari dataSource ), 'type' => 'bar', 'encode' => array( 'x' => 'amount', 'y' => 'product' ) ) ) ); if (count($rows) > 0) { $totalArray = array(); for ($i = 0; $i < count($rows); $i++) { if ($i < count($color)) { $totalArray[] = $rows[$i]['total']; } else { break; } } $maxTotal = max($totalArray); for ($i = 0; $i < count($rows); $i++) { if ($i < count($color)) { $percentage = (($rows[$i]['total'] / $maxTotal) * 100); $formattedPercentage = number_format($percentage, 2); $param['dataset']['source'][] = [ $color[$i], $rows[$i]['total'], $rows[$i]['Mcu_KelainanName'], $formattedPercentage, ]; } else { break; } } } // 3. encapsulate in config attribute and json encode $config = ["config" => $param]; $j_param = json_encode($config); // echo $j_param; header("Content-Type: image/png"); // 4. post to chart renderer echo $this->post($this->url_renderer, $j_param); } // --> MCU006 function mcu006($id) { // 1. prepare the data using sql $sql = 'SELECT case when Mgm_HeaderIsNormal = "Y" then "Normal" when Mgm_HeaderIsNormal = "N" then Mcu_KelainanName else "Tidak diperiksa" end as test , count(Mgm_HeaderT_OrderHeaderID) as total,Mcu_KelainanClasification FROM mgm_header left join mgm_detail on Mgm_DetailMgm_HeaderID = Mgm_HeaderID and Mgm_DetailIsActive = "Y" left join mcu_kelainan on Mgm_DetailMcu_KelainanID = Mcu_KelainanID left join mcu_kelainangroup on Mgm_DetailMcu_KelainanGroupID = Mcu_KelainanGroupID left join nat_test on Nat_TestCode = Mgm_HeaderNat_TestCode where Mgm_HeaderIsActive = "Y" and Mgm_HeaderMgm_McuID = ? and Mgm_HeaderNat_TestCode = "STATUS GIZI" group by case when Mgm_HeaderIsNormal = "Y" then "Normal" when Mgm_HeaderIsNormal = "N" then Mcu_KelainanName else "Tidak diperiksa" end ORDER BY count(Mgm_HeaderT_OrderHeaderID) DESC'; $qry = $this->db->query($sql, [$id]); $this->check_error($qry, "get total mcu"); $rows = $qry->result_array(); if (count($rows) == 0) { $this->chart_error("No data found"); } $data = []; if (count($rows) > 0) { foreach ($rows as $key => $vx) { $data[] = array( "value" => $vx['total'], "name" => "{$vx['test']} : {$vx['total']} Peserta" ); } } // 2. generate parameter for the chart $param = array( 'title' => array( 'text' => 'Status Index Massa Tubuh (BMI)', 'left' => 'center' ), 'tooltip' => array( 'trigger' => 'item' ), 'legend' => array( 'top' => '75%', 'left' => 'center', 'orient' => 'vertical' ), 'series' => array( array( 'label' => array( 'position' => 'inner', 'formatter' => '{d}%' ), 'name' => 'Access From', 'type' => 'pie', 'radius' => array('20%', '50%'), 'itemStyle' => array( 'borderRadius' => 10, 'borderColor' => '#fff', 'borderWidth' => 2 ), 'data' => $data, 'emphasis' => array( 'itemStyle' => array( 'shadowBlur' => 10, 'shadowOffsetX' => 0, 'shadowColor' => 'rgba(0, 0, 0, 0.5)' ) ) ) ) ); // 3. encapsulate in config attribute and json encode $config = ["config" => $param]; $j_param = json_encode($config); header("Content-Type: image/png"); // 4. post to chart renderer echo $this->post($this->url_renderer, $j_param); } // --> MCU007 function mcu007($id) { // 1. prepare the data using sql $sql = 'SELECT case when Mgm_HeaderIsNormal = "Y" then "Normal" when Mgm_HeaderIsNormal = "N" then Mcu_KelainanName else "Tidak diperiksa" end as test, count(Mgm_HeaderT_OrderHeaderID) as total, Mcu_KelainanClasification FROM mgm_header left join mgm_detail on Mgm_DetailMgm_HeaderID = Mgm_HeaderID and Mgm_DetailIsActive = "Y" left join mcu_kelainan on Mgm_DetailMcu_KelainanID = Mcu_KelainanID left join mcu_kelainangroup on Mgm_DetailMcu_KelainanGroupID = Mcu_KelainanGroupID left join nat_test on Nat_TestCode = Mgm_HeaderNat_TestCode where Mgm_HeaderIsActive = "Y" and Mgm_HeaderMgm_McuID = ? and Mgm_HeaderNat_TestCode = "TANDA VITAL" group by case when Mgm_HeaderIsNormal = "Y" then "Normal" when Mgm_HeaderIsNormal = "N" then Mcu_KelainanName else "Tidak diperiksa" end ORDER BY count(Mgm_HeaderT_OrderHeaderID) DESC'; $qry = $this->db->query($sql, [$id]); $this->check_error($qry, "get total mcu"); $rows = $qry->result_array(); if (count($rows) == 0) { $this->chart_error("No data found"); } $data = []; if (count($rows) > 0) { foreach ($rows as $key => $vx) { $data[] = array( "value" => $vx['total'], "name" => "{$vx['test']} : {$vx['total']} Peserta" ); } } // 2. generate parameter for the chart $param = array( 'title' => array( 'text' => 'Kriteria Hipertensi', 'left' => 'center' ), 'tooltip' => array( 'trigger' => 'item' ), 'legend' => array( 'top' => 'bottom', 'left' => 'center', 'orient' => 'vertical' ), 'series' => array( array( 'label' => array( 'position' => 'inner', 'formatter' => '{d}%' ), 'name' => 'Access From', 'type' => 'pie', 'radius' => array('20%', '50%'), 'itemStyle' => array( 'borderRadius' => 10, 'borderColor' => '#fff', 'borderWidth' => 2 ), 'data' => $data, 'emphasis' => array( 'itemStyle' => array( 'shadowBlur' => 10, 'shadowOffsetX' => 0, 'shadowColor' => 'rgba(0, 0, 0, 0.5)' ) ) ) ) ); // 3. encapsulate in config attribute and json encode $config = ["config" => $param]; $j_param = json_encode($config); header("Content-Type: image/png"); // 4. post to chart renderer echo $this->post($this->url_renderer, $j_param); } // --> MCU008 function mcu008($id) { // 1. prepare the data using sql $sql = 'SELECT case when Mgm_HeaderIsNormal = "Y" then "Normal" when Mgm_HeaderIsNormal = "N" then Mcu_KelainanName else "Tidak diperiksa" end as test , count(Mgm_HeaderT_OrderHeaderID) as total FROM mgm_header left join mgm_detail on Mgm_DetailMgm_HeaderID = Mgm_HeaderID and Mgm_DetailIsActive = "Y" left join mcu_kelainan on Mgm_DetailMcu_KelainanID = Mcu_KelainanID left join mcu_kelainangroup on Mgm_DetailMcu_KelainanGroupID = Mcu_KelainanGroupID left join nat_test on Nat_TestCode = Mgm_HeaderNat_TestCode where Mgm_HeaderIsActive = "Y" and Mgm_HeaderMgm_McuID = ? and Mgm_HeaderNat_TestCode = "VISUS JAUH" group by case when Mgm_HeaderIsNormal = "Y" then "Normal" when Mgm_HeaderIsNormal = "N" then Mcu_KelainanName else "Tidak diperiksa" end ORDER BY count(Mgm_HeaderT_OrderHeaderID) DESC'; $qry = $this->db->query($sql, [$id]); $this->check_error($qry, "get total mcu"); $rows = $qry->result_array(); if (count($rows) == 0) { $this->chart_error("No data found"); } $data = []; if (count($rows) > 0) { foreach ($rows as $key => $vx) { $data[] = array( "value" => $vx['total'], "name" => "{$vx['test']} : {$vx['total']} Peserta" ); } } // 2. generate parameter for the chart $param = array( 'title' => array( 'text' => 'Visus Jauh', 'left' => 'center' ), 'tooltip' => array( 'trigger' => 'item' ), 'legend' => array( 'top' => 'bottom', 'left' => 'center', 'orient' => 'vertical' ), 'series' => array( array( 'label' => array( 'position' => 'inner', 'formatter' => '{d}%' ), 'name' => 'Access From', 'type' => 'pie', 'radius' => array('20%', '50%'), 'itemStyle' => array( 'borderRadius' => 10, 'borderColor' => '#fff', 'borderWidth' => 2 ), 'data' => $data, 'emphasis' => array( 'itemStyle' => array( 'shadowBlur' => 10, 'shadowOffsetX' => 0, 'shadowColor' => 'rgba(0, 0, 0, 0.5)' ) ) ) ) ); // 3. encapsulate in config attribute and json encode $config = ["config" => $param]; $j_param = json_encode($config); header("Content-Type: image/png"); // 4. post to chart renderer echo $this->post($this->url_renderer, $j_param); } // --> MCU009 function mcu009($id) { // 1. prepare the data using sql $sql = "SELECT Mcu_KelainanName , count(Mgm_HeaderT_OrderHeaderID) as total FROM mgm_header join mgm_detail on Mgm_DetailMgm_HeaderID = Mgm_HeaderID and Mgm_DetailIsActive = 'Y' join mcu_kelainan on Mgm_DetailMcu_KelainanID = Mcu_KelainanID join mcu_kelainangroup on Mgm_DetailMcu_KelainanGroupID = Mcu_KelainanGroupID where Mgm_HeaderIsActive = 'Y' and Mgm_HeaderMgm_McuID = ? and Mgm_HeaderType = 'L' and Mgm_HeaderIsNormal = 'N' group by Mcu_KelainanID ORDER BY count(Mgm_HeaderT_OrderHeaderID) DESC LIMIT 10"; $qry = $this->db->query($sql, [$id]); $this->check_error($qry, "get total mcu"); $rows = $qry->result_array(); if (count($rows) == 0) { $this->chart_error("No data found"); } // 2. generate parameter for the chart $color = [ 200, 175, 150, 125, 100, 90, 80, 70, 60, 50, ]; $param = array( 'title' => array( //'text' => 'Kelainan Laboratorium', // 'subtext' => 'Living Expenses in Shenzhen' ), 'dataset' => array( 'source' => array( ['score', 'amount', 'product', 'percentage'], ), ), 'grid' => array( 'containLabel' => true ), 'xAxis' => array( 'name' => 'amount' ), 'yAxis' => array( 'type' => 'category' ), 'visualMap' => array( 'orient' => 'horizontal', 'left' => 'center', 'min' => 10, 'max' => 100, 'show' => false, 'dimension' => 0, 'inRange' => array( 'color' => array('#42aaf5', '#00eaf2', '#035bff') ) ), 'series' => array( array( 'label' => array( 'position' => 'right', 'show' => true, "formatter" => "{@[3]} %" // index ke 4 dari dataSource ), 'type' => 'bar', 'encode' => array( 'x' => 'amount', 'y' => 'product' ) ) ) ); if (count($rows) > 0) { $totalArray = array(); for ($i = 0; $i < count($rows); $i++) { if ($i < count($color)) { $totalArray[] = $rows[$i]['total']; } else { break; } } $maxTotal = max($totalArray); for ($i = 0; $i < count($rows); $i++) { if ($i < count($color)) { $percentage = (($rows[$i]['total'] / $maxTotal) * 100); $formattedPercentage = number_format($percentage, 2); $param['dataset']['source'][] = [ $color[$i], $rows[$i]['total'], $rows[$i]['Mcu_KelainanName'], $formattedPercentage ]; } else { break; } } } // 3. encapsulate in config attribute and json encode $config = ["config" => $param]; $j_param = json_encode($config); // echo $j_param; header("Content-Type: image/png"); // 4. post to chart renderer echo $this->post($this->url_renderer, $j_param); } // --> MCU010 function mcu010($id) { // 1. prepare the data using sql $sql = "SELECT Mcu_KelainanName , count(Mgm_HeaderT_OrderHeaderID) as total FROM mgm_header join mgm_detail on Mgm_DetailMgm_HeaderID = Mgm_HeaderID and Mgm_DetailIsActive = 'Y' join mcu_kelainan on Mgm_DetailMcu_KelainanID = Mcu_KelainanID join mcu_kelainangroup on Mgm_DetailMcu_KelainanGroupID = Mcu_KelainanGroupID where Mgm_HeaderIsActive = 'Y' and Mgm_HeaderMgm_McuID = ? and Mgm_HeaderType = 'L' and Mgm_HeaderIsNormal = 'N' and Mcu_KelainanGroupID = 14 group by Mcu_KelainanID ORDER BY count(Mgm_HeaderT_OrderHeaderID) DESC "; $qry = $this->db->query($sql, [$id]); $this->check_error($qry, "get total mcu"); $rows = $qry->result_array(); if (count($rows) == 0) { $this->chart_error("No data found"); } // 2. generate parameter for the chart $color = [ 89.3, 57.1, 74.4, 50.1, 89.7 ]; $param = array( 'title' => array( 'text' => 'Hematologi', // 'subtext' => 'Living Expenses in Shenzhen' ), 'dataset' => array( 'source' => array( ['score', 'amount', 'product', 'percentage'], ), ), 'grid' => array( 'containLabel' => true ), 'xAxis' => array( 'name' => 'amount' ), 'yAxis' => array( 'type' => 'category' ), 'visualMap' => array( 'orient' => 'horizontal', 'left' => 'center', 'min' => 10, 'max' => 100, 'show' => false, 'dimension' => 0, 'inRange' => array( 'color' => array('#42aaf5', '#00eaf2', '#035bff') ) ), 'series' => array( array( 'label' => array( 'position' => 'right', 'show' => true, "formatter" => "{@[3]} %" // index ke 4 dari dataSource ), 'type' => 'bar', 'encode' => array( 'x' => 'amount', 'y' => 'product' ) ) ) ); if (count($rows) > 0) { $totalArray = array(); for ($i = 0; $i < count($rows); $i++) { if ($i < count($color)) { $totalArray[] = $rows[$i]['total']; } else { break; } } $maxTotal = max($totalArray); for ($i = 0; $i < count($rows); $i++) { if ($i < count($color)) { $percentage = (($rows[$i]['total'] / $maxTotal) * 100); $formattedPercentage = number_format($percentage, 2); $param['dataset']['source'][] = [ $color[$i], $rows[$i]['total'], $rows[$i]['Mcu_KelainanName'], $formattedPercentage ]; } else { break; } } } // 3. encapsulate in config attribute and json encode $config = ["config" => $param]; $j_param = json_encode($config); // echo $j_param; header("Content-Type: image/png"); // 4. post to chart renderer echo $this->post($this->url_renderer, $j_param); } // --> MCU011 function mcu011($id) { // 1. prepare the data using sql $sql = "SELECT Mcu_KelainanName , count(Mgm_HeaderT_OrderHeaderID) as total FROM mgm_header join mgm_detail on Mgm_DetailMgm_HeaderID = Mgm_HeaderID and Mgm_DetailIsActive = 'Y' join mcu_kelainan on Mgm_DetailMcu_KelainanID = Mcu_KelainanID join mcu_kelainangroup on Mgm_DetailMcu_KelainanGroupID = Mcu_KelainanGroupID where Mgm_HeaderIsActive = 'Y' and Mgm_HeaderMgm_McuID = ? and Mgm_HeaderType = 'L' and Mgm_HeaderIsNormal = 'N' and Mcu_KelainanGroupID = 15 group by Mcu_KelainanID ORDER BY count(Mgm_HeaderT_OrderHeaderID) DESC "; $qry = $this->db->query($sql, [$id]); $this->check_error($qry, "get total mcu"); $rows = $qry->result_array(); if (count($rows) == 0) { $this->chart_error("No data found"); } // 2. generate parameter for the chart $color = [ 89.3, 57.1, 74.4, 50.1, 89.7 ]; $param = array( 'title' => array( 'text' => 'Urinalisa', ), 'dataset' => array( 'source' => array( array('score', 'amount', 'product'), ) ), 'grid' => array('containLabel' => true), 'yAxis' => array('name' => ''), 'xAxis' => array('type' => 'category'), 'visualMap' => array( 'orient' => 'horizontal', 'show' => false, 'left' => 'center', 'min' => 10, 'max' => 100, 'dimension' => 0, 'inRange' => array( 'color' => array('#42aaf5', '#00eaf2', '#035bff') ) ), 'series' => array( array( 'type' => 'bar', 'label' => array( 'show' => true, 'position' => 'inside' ), 'encode' => array( 'y' => 'amount', 'x' => 'product' ) ) ) ); if (count($rows) > 0) { $totalArray = array(); for ($i = 0; $i < count($rows); $i++) { if ($i < count($color)) { $totalArray[] = $rows[$i]['total']; } else { break; } } $maxTotal = max($totalArray); for ($i = 0; $i < count($rows); $i++) { if ($i < count($color)) { // $percentage = (($rows[$i]['total'] / $maxTotal) * 100); // $formattedPercentage = number_format($percentage, 2); $param['dataset']['source'][] = [ $color[$i], $rows[$i]['total'], $rows[$i]['Mcu_KelainanName'], // $formattedPercentage ]; } else { break; } } } // 3. encapsulate in config attribute and json encode $config = ["config" => $param]; $j_param = json_encode($config); // echo $j_param; header("Content-Type: image/png"); // 4. post to chart renderer echo $this->post($this->url_renderer, $j_param); } // --> MCU012 function mcu012($id) { // 1. prepare the data using sql $sql = "SELECT Mcu_KelainanName , count(Mgm_HeaderT_OrderHeaderID) as total FROM mgm_header join mgm_detail on Mgm_DetailMgm_HeaderID = Mgm_HeaderID and Mgm_DetailIsActive = 'Y' join mcu_kelainan on Mgm_DetailMcu_KelainanID = Mcu_KelainanID join mcu_kelainangroup on Mgm_DetailMcu_KelainanGroupID = Mcu_KelainanGroupID where Mgm_HeaderIsActive = 'Y' and Mgm_HeaderMgm_McuID = ? and Mgm_HeaderType = 'L' and Mgm_HeaderIsNormal = 'N' and Mcu_KelainanGroupID = 16 group by Mcu_KelainanID ORDER BY count(Mgm_HeaderT_OrderHeaderID) DESC "; $qry = $this->db->query($sql, [$id]); $this->check_error($qry, "get total mcu"); $rows = $qry->result_array(); if (count($rows) == 0) { $this->chart_error("No data found"); } // 2. generate parameter for the chart $color = [ 89.3, 57.1, ]; $param = array( 'title' => array( 'text' => 'Gangguan Fungsi Hati', ), 'dataset' => array( 'source' => array( array('score', 'amount', 'product'), ) ), 'grid' => array('containLabel' => true), 'yAxis' => array('name' => ''), 'xAxis' => array('type' => 'category'), 'visualMap' => array( 'orient' => 'horizontal', 'show' => false, 'left' => 'center', 'min' => 10, 'max' => 100, 'dimension' => 0, 'inRange' => array( 'color' => array('#42aaf5', '#00eaf2', '#035bff') ) ), 'series' => array( array( 'type' => 'bar', 'label' => array( 'show' => true, 'position' => 'inside' ), 'encode' => array( 'y' => 'amount', 'x' => 'product' ) ) ) ); if (count($rows) > 0) { $totalArray = array(); for ($i = 0; $i < count($rows); $i++) { if ($i < count($color)) { $totalArray[] = $rows[$i]['total']; } else { break; } } $maxTotal = max($totalArray); for ($i = 0; $i < count($rows); $i++) { if ($i < count($color)) { // $percentage = (($rows[$i]['total'] / $maxTotal) * 100); // $formattedPercentage = number_format($percentage, 2); $param['dataset']['source'][] = [ $color[$i], $rows[$i]['total'], $rows[$i]['Mcu_KelainanName'], // $formattedPercentage ]; } else { break; } } } // 3. encapsulate in config attribute and json encode $config = ["config" => $param]; $j_param = json_encode($config); // echo $j_param; header("Content-Type: image/png"); // 4. post to chart renderer echo $this->post($this->url_renderer, $j_param); } // --> MCU013 function mcu013($id) { // 1. prepare the data using sql $sql = "SELECT ifnull(Mcu_KelainanName,'Normal') as test , count(Mgm_HeaderT_OrderHeaderID) as total FROM mgm_header left join mgm_detail on Mgm_DetailMgm_HeaderID = Mgm_HeaderID and Mgm_DetailIsActive = 'Y' left join mcu_kelainan on Mgm_DetailMcu_KelainanID = Mcu_KelainanID left join mcu_kelainangroup on Mgm_DetailMcu_KelainanGroupID = Mcu_KelainanGroupID where Mgm_HeaderIsActive = 'Y' and Mgm_HeaderNat_TestCode IN ( '10520300','10520400') and Mgm_HeaderMgm_McuID = ? group by Mcu_KelainanID"; $qry = $this->db->query($sql, [$id]); $this->check_error($qry, "get total mcu"); $rows = $qry->result_array(); if (count($rows) == 0) { $this->chart_error("No data found"); } // 2. generate parameter for the chart $color = [ 89.3, 57.1, ]; $param = array( 'title' => array( 'text' => 'Gangguan Metabolisme Lemak', ), 'dataset' => array( 'source' => array( array('score', 'amount', 'product'), ) ), 'grid' => array('containLabel' => true), 'yAxis' => array('name' => ''), 'xAxis' => array('type' => 'category'), 'visualMap' => array( 'orient' => 'horizontal', 'show' => false, 'left' => 'center', 'min' => 10, 'max' => 100, 'dimension' => 0, 'inRange' => array( 'color' => array('#42aaf5', '#00eaf2', '#035bff') ) ), 'series' => array( array( 'type' => 'bar', 'label' => array( 'show' => true, 'position' => 'inside' ), 'encode' => array( 'y' => 'amount', 'x' => 'product' ) ) ) ); if (count($rows) > 0) { $totalArray = array(); for ($i = 0; $i < count($rows); $i++) { if ($i < count($color)) { $totalArray[] = $rows[$i]['total']; } else { break; } } $maxTotal = max($totalArray); for ($i = 0; $i < count($rows); $i++) { if ($i < count($color)) { // $percentage = (($rows[$i]['total'] / $maxTotal) * 100); // $formattedPercentage = number_format($percentage, 2); $param['dataset']['source'][] = [ $color[$i], $rows[$i]['total'], $rows[$i]['test'], // $formattedPercentage ]; } else { break; } } } // 3. encapsulate in config attribute and json encode $config = ["config" => $param]; $j_param = json_encode($config); // echo $j_param; header("Content-Type: image/png"); // 4. post to chart renderer echo $this->post($this->url_renderer, $j_param); } // --> MCU014 function mcu014($id) { // 1. prepare the data using sql $sql = " SELECT ifnull(Mcu_KelainanName,'Normal') as test , count(Mgm_HeaderT_OrderHeaderID) as total FROM mgm_header left join mgm_detail on Mgm_DetailMgm_HeaderID = Mgm_HeaderID and Mgm_DetailIsActive = 'Y' left join mcu_kelainan on Mgm_DetailMcu_KelainanID = Mcu_KelainanID left join mcu_kelainangroup on Mgm_DetailMcu_KelainanGroupID = Mcu_KelainanGroupID where Mgm_HeaderIsActive = 'Y' and Mgm_HeaderNat_TestCode = 10540200 and Mgm_HeaderMgm_McuID = ? group by Mcu_KelainanID"; $qry = $this->db->query($sql, [$id]); $this->check_error($qry, "get total mcu"); $rows = $qry->result_array(); if (count($rows) == 0) { $this->chart_error("No data found"); } // 2. generate parameter for the chart $color = [ 89.3, 57.1, ]; $param = array( 'title' => array( 'text' => 'Peningkatan Glukosa', ), 'dataset' => array( 'source' => array( array('score', 'amount', 'product'), ) ), 'grid' => array('containLabel' => true), 'yAxis' => array('name' => ''), 'xAxis' => array('type' => 'category'), 'visualMap' => array( 'orient' => 'horizontal', 'show' => false, 'left' => 'center', 'min' => 10, 'max' => 100, 'dimension' => 0, 'inRange' => array( 'color' => array('#42aaf5', '#00eaf2', '#035bff') ) ), 'series' => array( array( 'type' => 'bar', 'label' => array( 'show' => true, 'position' => 'inside' ), 'encode' => array( 'y' => 'amount', 'x' => 'product' ) ) ) ); if (count($rows) > 0) { $totalArray = array(); for ($i = 0; $i < count($rows); $i++) { if ($i < count($color)) { $totalArray[] = $rows[$i]['total']; } else { break; } } $maxTotal = max($totalArray); for ($i = 0; $i < count($rows); $i++) { if ($i < count($color)) { // $percentage = (($rows[$i]['total'] / $maxTotal) * 100); // $formattedPercentage = number_format($percentage, 2); $param['dataset']['source'][] = [ $color[$i], $rows[$i]['total'], $rows[$i]['test'], // $formattedPercentage ]; } else { break; } } } // 3. encapsulate in config attribute and json encode $config = ["config" => $param]; $j_param = json_encode($config); // echo $j_param; header("Content-Type: image/png"); // 4. post to chart renderer echo $this->post($this->url_renderer, $j_param); } // --> MCU015 function mcu015($id) { // 1. prepare the data using sql $sql = "SELECT concat(Nat_TestName,'/',Mcu_KelainanName) as kelainan, count(Mgm_HeaderT_OrderHeaderID) as total FROM mgm_header left join mgm_detail on Mgm_DetailMgm_HeaderID = Mgm_HeaderID and Mgm_DetailIsActive = 'Y' left join mcu_kelainan on Mgm_DetailMcu_KelainanID = Mcu_KelainanID left join mcu_kelainangroup on Mgm_DetailMcu_KelainanGroupID = Mcu_KelainanGroupID left join nat_test on Nat_TestCode = Mgm_HeaderNat_TestCode where Mgm_HeaderIsActive = 'Y' and Mgm_HeaderMgm_McuID = ? and Mgm_HeaderType = 'NL' and Mgm_HeaderIsNormal = 'N' group by Mcu_KelainanID ORDER BY count(Mgm_HeaderT_OrderHeaderID) DESC LIMIT 10"; $qry = $this->db->query($sql, [$id]); $this->check_error($qry, "get total mcu"); $rows = $qry->result_array(); if (count($rows) == 0) { $this->chart_error("No data found"); } // 2. generate parameter for the chart $color = [ 200, 175, 150, 125, 100, 90, 80, 70, 60, 50, ]; $param = array( 'title' => array( // 'text' => 'Kelainan Fisik', // 'subtext' => 'Living Expenses in Shenzhen' ), 'dataset' => array( 'source' => array( ['score', 'amount', 'product', 'percentage'], ), ), 'grid' => array( 'containLabel' => true ), 'xAxis' => array( 'name' => 'amount' ), 'yAxis' => array( 'type' => 'category' ), 'visualMap' => array( 'orient' => 'horizontal', 'left' => 'center', 'min' => 10, 'max' => 100, 'show' => false, 'dimension' => 0, 'inRange' => array( 'color' => array('#42aaf5', '#00eaf2', '#035bff') ) ), 'series' => array( array( 'label' => array( 'position' => 'right', 'show' => true, "formatter" => "{@[3]} %" // index ke 4 dari dataSource ), 'type' => 'bar', 'encode' => array( 'x' => 'amount', 'y' => 'product' ) ) ) ); if (count($rows) > 0) { $totalArray = array(); for ($i = 0; $i < count($rows); $i++) { if ($i < count($color)) { $totalArray[] = $rows[$i]['total']; } else { break; } } $maxTotal = max($totalArray); for ($i = 0; $i < count($rows); $i++) { if ($i < count($color)) { $percentage = (($rows[$i]['total'] / $maxTotal) * 100); $formattedPercentage = number_format($percentage, 2); $param['dataset']['source'][] = [ $color[$i], $rows[$i]['total'], $rows[$i]['kelainan'], $formattedPercentage ]; } else { break; } } } // 3. encapsulate in config attribute and json encode $config = ["config" => $param]; $j_param = json_encode($config); // echo $j_param; header("Content-Type: image/png"); // 4. post to chart renderer echo $this->post($this->url_renderer, $j_param); } // --> MCU016 function mcu016($id) { // 1. prepare the data using sql $sql = " SELECT ifnull(Mcu_KelainanName,'Normal') as test, count(Mgm_HeaderT_OrderHeaderID) as total FROM mgm_header left join mgm_detail on Mgm_DetailMgm_HeaderID = Mgm_HeaderID and Mgm_DetailIsActive = 'Y' left join mcu_kelainan on Mgm_DetailMcu_KelainanID = Mcu_KelainanID left join mcu_kelainangroup on Mgm_DetailMcu_KelainanGroupID = Mcu_KelainanGroupID where Mgm_HeaderIsActive = 'Y' and Mgm_HeaderNat_TestCode = 20120100 and Mgm_HeaderIsNormal = 'N' and Mgm_HeaderMgm_McuID = ? group by Mcu_KelainanID"; $qry = $this->db->query($sql, [$id]); $this->check_error($qry, "get total mcu"); $rows = $qry->result_array(); if (count($rows) == 0) { $this->chart_error("No data found"); } // 2. generate parameter for the chart $color = [ 89.3, 57.1, 74.4, 50.1, 89.7, 66.7 ]; $param = array( 'title' => array( 'text' => 'Gangguan Jantung', ), 'dataset' => array( 'source' => array( array('score', 'amount', 'product'), ) ), 'grid' => array('containLabel' => true), 'yAxis' => array('name' => ''), 'xAxis' => array('type' => 'category'), 'visualMap' => array( 'orient' => 'horizontal', 'show' => false, 'left' => 'center', 'min' => 10, 'max' => 100, 'dimension' => 0, 'inRange' => array( 'color' => array('#42aaf5', '#00eaf2', '#035bff') ) ), 'series' => array( array( 'type' => 'bar', 'label' => array( 'show' => true, 'position' => 'inside' ), 'encode' => array( 'y' => 'amount', 'x' => 'product' ) ) ) ); if (count($rows) > 0) { $totalArray = array(); for ($i = 0; $i < count($rows); $i++) { if ($i < count($color)) { $totalArray[] = $rows[$i]['total']; } else { break; } } $maxTotal = max($totalArray); for ($i = 0; $i < count($rows); $i++) { if ($i < count($color)) { // $percentage = (($rows[$i]['total'] / $maxTotal) * 100); // $formattedPercentage = number_format($percentage, 2); $param['dataset']['source'][] = [ $color[$i], $rows[$i]['total'], $rows[$i]['test'], // $formattedPercentage ]; } else { break; } } } // 3. encapsulate in config attribute and json encode $config = ["config" => $param]; $j_param = json_encode($config); // echo $j_param; header("Content-Type: image/png"); // 4. post to chart renderer echo $this->post($this->url_renderer, $j_param); } // --> MCU017 function mcu017($id) { // 1. prepare the data using sql $sql = " SELECT ifnull(Mcu_KelainanName,'Normal') as test, count(Mgm_HeaderT_OrderHeaderID) as total FROM mgm_header left join mgm_detail on Mgm_DetailMgm_HeaderID = Mgm_HeaderID and Mgm_DetailIsActive = 'Y' left join mcu_kelainan on Mgm_DetailMcu_KelainanID = Mcu_KelainanID left join mcu_kelainangroup on Mgm_DetailMcu_KelainanGroupID = Mcu_KelainanGroupID where Mgm_HeaderIsActive = 'Y' and Mgm_HeaderNat_TestCode = 30150100 and Mgm_HeaderIsNormal = 'N' and Mgm_HeaderMgm_McuID = ? group by Mcu_KelainanID"; $qry = $this->db->query($sql, [$id]); $this->check_error($qry, "get total mcu"); $rows = $qry->result_array(); if (count($rows) == 0) { $this->chart_error("No data found"); } // 2. generate parameter for the chart $color = [ 89.3, 57.1, 74.4, 50.1, ]; $param = array( 'title' => array( 'text' => 'Thorax PA', ), 'dataset' => array( 'source' => array( array('score', 'amount', 'product'), ) ), 'grid' => array('containLabel' => true), 'yAxis' => array('name' => ''), 'xAxis' => array('type' => 'category'), 'visualMap' => array( 'orient' => 'horizontal', 'show' => false, 'left' => 'center', 'min' => 10, 'max' => 100, 'dimension' => 0, 'inRange' => array( 'color' => array('#42aaf5', '#00eaf2', '#035bff') ) ), 'series' => array( array( 'type' => 'bar', 'label' => array( 'show' => true, 'position' => 'inside' ), 'encode' => array( 'y' => 'amount', 'x' => 'product' ) ) ) ); if (count($rows) > 0) { $totalArray = array(); for ($i = 0; $i < count($rows); $i++) { if ($i < count($color)) { $totalArray[] = $rows[$i]['total']; } else { break; } } $maxTotal = max($totalArray); for ($i = 0; $i < count($rows); $i++) { if ($i < count($color)) { // $percentage = (($rows[$i]['total'] / $maxTotal) * 100); // $formattedPercentage = number_format($percentage, 2); $param['dataset']['source'][] = [ $color[$i], $rows[$i]['total'], $rows[$i]['test'], // $formattedPercentage ]; } else { break; } } } // 3. encapsulate in config attribute and json encode $config = ["config" => $param]; $j_param = json_encode($config); // echo $j_param; header("Content-Type: image/png"); // 4. post to chart renderer echo $this->post($this->url_renderer, $j_param); } // --> MCU018 function mcu018($id) { // 1. prepare the data using sql $sql = " SELECT ifnull(Mcu_KelainanName,'Normal') as test, count(Mgm_HeaderT_OrderHeaderID) as total FROM mgm_header left join mgm_detail on Mgm_DetailMgm_HeaderID = Mgm_HeaderID and Mgm_DetailIsActive = 'Y' left join mcu_kelainan on Mgm_DetailMcu_KelainanID = Mcu_KelainanID left join mcu_kelainangroup on Mgm_DetailMcu_KelainanGroupID = Mcu_KelainanGroupID where Mgm_HeaderIsActive = 'Y' and Mgm_HeaderNat_TestCode = 20140100 and Mgm_HeaderIsNormal = 'N' and Mgm_HeaderMgm_McuID = ? group by Mcu_KelainanID "; $qry = $this->db->query($sql, [$id]); $this->check_error($qry, "get total mcu"); $rows = $qry->result_array(); if (count($rows) == 0) { $this->chart_error("No data found"); } // 2. generate parameter for the chart $color = [ 89.3, 57.1, 74.4, 50.1, 67.1, ]; $param = array( 'title' => array( 'text' => 'Kelainan Autospirometri', ), 'dataset' => array( 'source' => array( array('score', 'amount', 'product'), ) ), 'grid' => array('containLabel' => true), 'yAxis' => array('name' => ''), 'xAxis' => array('type' => 'category'), 'visualMap' => array( 'orient' => 'horizontal', 'show' => false, 'left' => 'center', 'min' => 10, 'max' => 100, 'dimension' => 0, 'inRange' => array( 'color' => array('#42aaf5', '#00eaf2', '#035bff') ) ), 'series' => array( array( 'type' => 'bar', 'label' => array( 'show' => true, 'position' => 'inside' ), 'encode' => array( 'y' => 'amount', 'x' => 'product' ) ) ) ); if (count($rows) > 0) { $totalArray = array(); for ($i = 0; $i < count($rows); $i++) { if ($i < count($color)) { $totalArray[] = $rows[$i]['total']; } else { break; } } $maxTotal = max($totalArray); for ($i = 0; $i < count($rows); $i++) { if ($i < count($color)) { // $percentage = (($rows[$i]['total'] / $maxTotal) * 100); // $formattedPercentage = number_format($percentage, 2); $param['dataset']['source'][] = [ $color[$i], $rows[$i]['total'], $rows[$i]['test'], // $formattedPercentage ]; } else { break; } } } // 3. encapsulate in config attribute and json encode $config = ["config" => $param]; $j_param = json_encode($config); // echo $j_param; header("Content-Type: image/png"); // 4. post to chart renderer echo $this->post($this->url_renderer, $j_param); } // --> MCU019 function mcu019($id) { // 1. prepare the data using sql $sql = "SELECT ifnull(Mcu_KelainanName,'Normal') as test , count(Mgm_HeaderT_OrderHeaderID) as total FROM mgm_header left join mgm_detail on Mgm_DetailMgm_HeaderID = Mgm_HeaderID and Mgm_DetailIsActive = 'Y' left join mcu_kelainan on Mgm_DetailMcu_KelainanID = Mcu_KelainanID left join mcu_kelainangroup on Mgm_DetailMcu_KelainanGroupID = Mcu_KelainanGroupID where Mgm_HeaderIsActive = 'Y' and Mgm_HeaderNat_TestCode = 20130100 and Mgm_HeaderIsNormal = 'N' and Mgm_HeaderMgm_McuID = ? group by Mcu_KelainanID "; $qry = $this->db->query($sql, [$id]); $this->check_error($qry, "get total mcu"); $rows = $qry->result_array(); if (count($rows) == 0) { $this->chart_error("No data found"); } // 2. generate parameter for the chart $color = [ 89.3, 57.1, 74.4, ]; $param = array( 'title' => array( 'text' => 'Gangguan Pendengaran', ), 'dataset' => array( 'source' => array( array('score', 'amount', 'product'), ) ), 'grid' => array('containLabel' => true), 'yAxis' => array('name' => ''), 'xAxis' => array('type' => 'category'), 'visualMap' => array( 'orient' => 'horizontal', 'show' => false, 'left' => 'center', 'min' => 10, 'max' => 100, 'dimension' => 0, 'inRange' => array( 'color' => array('#42aaf5', '#00eaf2', '#035bff') ) ), 'series' => array( array( 'type' => 'bar', 'label' => array( 'show' => true, 'position' => 'inside' ), 'encode' => array( 'y' => 'amount', 'x' => 'product' ) ) ) ); if (count($rows) > 0) { $totalArray = array(); for ($i = 0; $i < count($rows); $i++) { if ($i < count($color)) { $totalArray[] = $rows[$i]['total']; } else { break; } } $maxTotal = max($totalArray); for ($i = 0; $i < count($rows); $i++) { if ($i < count($color)) { // $percentage = (($rows[$i]['total'] / $maxTotal) * 100); // $formattedPercentage = number_format($percentage, 2); $param['dataset']['source'][] = [ $color[$i], $rows[$i]['total'], $rows[$i]['test'], // $formattedPercentage ]; } else { break; } } } // 3. encapsulate in config attribute and json encode $config = ["config" => $param]; $j_param = json_encode($config); // echo $j_param; header("Content-Type: image/png"); // 4. post to chart renderer echo $this->post($this->url_renderer, $j_param); } function check_error($qry, $stage) { if (!$qry) { $errMsg = $stage . "
" . $this->db->error()["messge"]; print_r($errMsg); $this->chart_error($errMsg); } } function chart_error($msg) { $param = array( 'title' => array( 'show' => true, 'textStyle' => array( 'color' => 'grey', 'fontSize' => 20 ), 'text' => "", 'left' => 'center', 'top' => 'center' ), 'xAxis' => array( 'show' => false ), 'yAxis' => array( 'show' => false ), 'series' => array() ); header("Content-Type: image/png"); $config = ["config" => $param]; $j_param = json_encode($config); echo $this->post($this->url_renderer, $j_param); exit; } function post($url, $data) { $ch = curl_init($url); curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST"); curl_setopt($ch, CURLOPT_POSTFIELDS, $data); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 5); curl_setopt($ch, CURLOPT_TIMEOUT, j120); curl_setopt($ch, CURLOPT_HTTPHEADER, [ "Content-Type: application/json", "Content-Length: " . strlen($data), ]); $result = curl_exec($ch); if (curl_errno($ch) > 0) { return [ "status" => "ERR", "message" => curl_error($ch), ]; } $httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE); if ($httpCode != 200) { return [ "status" => "ERR", "message" => "Http Response : $httpCode", ]; } return $result; } }