| Current Path : /var/www/html/sprm/backend/views/report-graph/ |
| Current File : /var/www/html/sprm/backend/views/report-graph/view.php |
<?php
use yii\helpers\Html;
use yii\widgets\DetailView;
/* @var $this yii\web\View */
/* @var $model backend\models\ReportGraph */
$this->title = $model->title_graph;
$this->params['breadcrumbs'][] = ['label' => 'Report Graphs', 'url' => ['index']];
$this->params['breadcrumbs'][] = $this->title;
$request = Yii::$app->request->get('ReportGraph');
$xAxis = $request['xAxis'];
$yAxis = $request['yAxis'];
$graph_type = $request['graph_type'];
$table_name = $request['table_name'];
$title_graph = $request['title_graph'];
$yAxis_replacement_name = $request['yAxis_replacement_name'];
$id_report_meta = $request['id_report_meta'];
$sql_statement = $request['sql_statement'];
$type_report = $request['type_report'];
$id_report_graph = $request['id_report_graph'];
?>
<div class="wrapper wrapper-content animated fadeInRight" style="padding: 20px 10px 0px;">
<div class="row">
<div class="col-lg-12">
<div class="ibox float-e-margins">
<div class="ibox-title" style="background-color: <?php echo $modelSkin->form_layout_bgcolour; ?>">
<h5><?= Html::encode($this->title) ?></h5>
<div class="ibox-tools" >
<a class="collapse-link">
<i class="fa fa-chevron-up"></i>
</a>
<a class="dropdown-toggle" data-toggle="dropdown" href="#">
<i class="fa fa-wrench"></i>
</a>
<ul class="dropdown-menu dropdown-user">
<li><a href="#">Config option 1</a>
</li>
<li><a href="#">Config option 2</a>
</li>
</ul>
<a class="close-link">
<i class="fa fa-times"></i>
</a>
</div>
</div>
<div class="ibox-content" style="background-color: <?php echo $modelSkin->form_layout_bgcolour; ?>">
<div class="table-responsive">
<p>
<?= Html::a('Update', ['update', 'ReportGraph[id_report_graph]' => $model->id_report_graph], ['class' => 'btn btn-primary']) ?>
<?= Html::a('Report', "index.php?r=report-graph/view1&ReportGraph[id_report_meta]=".$model->id_report_meta."&ReportGraph[title_graph]=".$model->title_graph."&ReportGraph[table_name]=".$model->table_name."&ReportGraph[sql_statement]=".$model->sql_statement."&ReportGraph[xAxis]=".$model->xAxis."&ReportGraph[yAxis]=".$model->yAxis."&ReportGraph[yAxis_replacement_name]=".$model->yAxis_replacement_name."&ReportGraph[type_report]=".$model->type_report."&ReportGraph[graph_type]=".$model->graph_type."&ReportGraph[id_report_graph]=".$model->id_report_graph, ['class' => 'btn btn-success']) ?>
<?= Html::a('Delete', ['delete', 'id_report_graph' => $model->id_report_graph], [
'class' => 'btn btn-danger',
'data' => [
'confirm' => 'Are you sure you want to delete this item?',
'method' => 'post',
],
]) ?>
</p>
<style type="text/css">
div.mybox {
border: 2px solid grey;
text-align: center;
padding: 10px;
}
.table > thead:first-child > tr:first-child > th{
text-align: center;
}
</style>
<div class="mybox">
<?= Html::img('images/logo.png',['width' => '20%','text-align'=>'center']) ?>
</br>
</br>
<script src="https://code.highcharts.com/highcharts.js"></script>
<script src="https://code.highcharts.com/modules/exporting.js"></script>
<script
src="https://code.jquery.com/jquery-3.2.1.slim.min.js"
integrity="sha256-k2WSCIexGzOj3Euiig+TlR8gA0EmPjuc79OEeY5L45g="
crossorigin="anonymous"></script>
<div id="containerChart" style="min-width: 300px; height: 400px; margin: 0 auto"></div>
<?php if ($sql_statement == ""){ ?>
<script>
$(document).ready(function() {
$.ajax({
url: 'index.php?r=report-graph/graph&ReportGraph[id_report_meta]='+<?php echo $id_report_meta ?>+'&ReportGraph[title_graph]='+JSON.stringify('<?php echo $title_graph ?>')+'&ReportGraph[table_name]='+<?php echo $table_name ?>+'&ReportGraph[xAxis]='+<?php echo $xAxis ?>+'&ReportGraph[yAxis]='+<?php echo $yAxis ?>+'&ReportGraph[yAxis_replacement_name]='+JSON.stringify('<?php echo $yAxis_replacement_name ?>')+'&ReportGraph[type_report]='+JSON.stringify('<?php echo $type_report ?>')+'&ReportGraph[graph_type]='+JSON.stringify('<?php echo $graph_type ?>')+'&ReportGraph[id_report_graph]='+<?php echo $id_report_graph ?>,
type: 'GET',
async: true,
dataType: "json",
success: function (data) {
var processed_json = new Array();
var xAXIS = new Array();
for(i = 0; i < data.length; i++){
processed_json.push([data[i].AXISX, parseInt(data[i].AXISY)]);
xAXIS.push([data[i].AXISX]);
}
renderChart(processed_json,xAXIS);
}
});
});
function renderChart(data,xAXIS){
Highcharts.chart('containerChart', {
chart: {
type: '<?php echo $graph_type ?>'
},
title: {
text: '<?php echo $title_graph ?>'
},
subtitle: {
text: ''
},
xAxis: {
type: '<?php echo $var_xAxis ?>',
categories: xAXIS,
labels: {
rotation: -45,
style: {
fontSize: '13px',
fontFamily: 'Verdana, sans-serif'
}
}
},
yAxis: {
min: 0,
title: {
text: '<?php echo $yAxis_replacement_name ?>'
}
},
legend: {
enabled: true
},
tooltip: {
pointFormat: 'Negeri: <b>{point.y:.1f} </b>'
},
series: [{
name: 'Population',
data: data,
dataLabels: {
enabled: true,
rotation: -90,
color: '#FFFFFF',
align: 'right',
format: '{point.y:.1f}', // one decimal
y: 10, // 10 pixels down from the top
style: {
fontSize: '13px',
fontFamily: 'Verdana, sans-serif'
}
}
}]
});
}
</script>
<?php }else{ ?>
<script>
$(document).ready(function() {
$.ajax({
url:'index.php?r=report-graph/graph&ReportGraph[id_report_meta]='+<?php echo $id_report_meta ?>+'&ReportGraph[title_graph]='+JSON.stringify('<?php echo $title_graph ?>')+'&ReportGraph[sql_statement]='+JSON.stringify("<?php echo $sql_statement ?>")+'&ReportGraph[yAxis_replacement_name]='+JSON.stringify('<?php echo $yAxis_replacement_name ?>')+'&ReportGraph[type_report]='+JSON.stringify('<?php echo $type_report ?>')+'&ReportGraph[graph_type]='+JSON.stringify('<?php echo $graph_type ?>')+'&ReportGraph[id_report_graph]='+<?php echo $id_report_graph ?>,
// url:'index.php?r=report-graph/graph&ReportGraph[id_report_meta]=3&ReportGraph[title_graph]=bn&ReportGraph[sql_statement]=SELECT%20untuk_pejabat_respons%20AS%20AXISX%20,%20COUNT%20(username)%20AS%20AXISY%20FROM%20databank_1011%20GROUP%20BY%20untuk_pejabat_respons&ReportGraph[xAxis]=&ReportGraph[yAxis]=&ReportGraph[yAxis_replacement_name]=gghhg&ReportGraph[type_report]=GRAPH&ReportGraph[graph_type]=area&ReportGraph[id_report_graph]=2010',
type: 'GET',
async: true,
dataType: "json",
success: function (data) {
var processed_json = new Array();
var xAXIS = new Array();
for(i = 0; i < data.length; i++){
processed_json.push([data[i].AXISX, parseInt(data[i].AXISY)]);
xAXIS.push([data[i].AXISX]);
}
console.log(data);
renderChart(processed_json,xAXIS);
}
});
});
function renderChart(data,xAXIS){
Highcharts.chart('containerChart', {
chart: {
type: '<?php echo $graph_type ?>'
},
title: {
text: '<?php echo $title_graph ?>'
},
subtitle: {
text: ''
},
xAxis: {
type: '<?php echo $var_xAxis ?>',
categories: xAXIS,
labels: {
rotation: -45,
style: {
fontSize: '13px',
fontFamily: 'Verdana, sans-serif'
}
}
},
yAxis: {
min: 0,
title: {
text: '<?php echo $yAxis_replacement_name ?>'
}
},
legend: {
enabled: true
},
tooltip: {
pointFormat: 'Negeri: <b>{point.y:.1f} </b>'
},
series: [{
name: 'Population',
data: data,
dataLabels: {
enabled: true,
rotation: -90,
color: '#FFFFFF',
align: 'right',
format: '{point.y:.1f}', // one decimal
y: 10, // 10 pixels down from the top
style: {
fontSize: '13px',
fontFamily: 'Verdana, sans-serif'
}
}
}]
});
}
</script>
<?php } ?>
</div>
<br>
<br>
<?= DetailView::widget([
'model' => $model,
'attributes' => [
'id_report_graph',
[
'attribute' => 'id_report_meta',
'headerOptions' => ['style' => 'text-align:center;'],
//'contentOptions' => ['style' => 'text-align:center;'],
'value' => $model->reportMeta->title_report_meta,
],
'title_graph',
[
'attribute' => 'table_name',
'headerOptions' => ['style' => 'text-align:center;'],
//'contentOptions' => ['style' => 'text-align:center;'],
'value' => function ($model)
{
if($model->sql_statement!=""){
return $model->table_name;
}else{
$getTable=Yii::$app->db->schema->getTableNames();
$dbTable = $getTable[$model->table_name];
return $dbTable;
}
},
],
'sql_statement',
[
'attribute' => 'xAxis',
'headerOptions' => ['style' => 'text-align:center;'],
//'contentOptions' => ['style' => 'text-align:center;'],
'value' => function ($model)
{
if($model->sql_statement!=""){
$getDb=Yii::$app->db->createCommand($model->sql_statement)->queryColumn();
$dbSelect = $getDb[$model->xAxis];
return $dbSelect;
}else{
$getDb=Yii::$app->db->schema->getTableNames();
$dbSelect = $getDb[$model->table_name];
$getTable=Yii::$app->db->getTableSchema($dbSelect)->getColumnNames();
$dbTable = $getTable[$model->xAxis];
return $dbTable;
}
},
],
[
'attribute' => 'yAxis',
'headerOptions' => ['style' => 'text-align:center;'],
//'contentOptions' => ['style' => 'text-align:center;'],
'value' => function ($model)
{
if($model->sql_statement!=""){
$getDb=Yii::$app->db->createCommand($model->sql_statement)->queryColumn();
$dbSelect = $getDb[$model->yAxis];
return $dbSelect;
}else{
$getDb=Yii::$app->db->schema->getTableNames();
$dbSelect = $getDb[$model->table_name];
$getTable=Yii::$app->db->getTableSchema($dbSelect)->getColumnNames();
$dbTable = $getTable[$model->yAxis];
return $dbTable;
}
},
],
'yAxis_replacement_name',
'type_report',
[
'attribute' => 'graph_type',
'headerOptions' => ['style' => 'text-align:center;'],
//'contentOptions' => ['style' => 'text-align:center;'],
'value' => $model->graph,
],
'created_at',
'created_by',
'updated_at',
'updated_by',
],
]) ?>
</div>
</div>
</div>
</div>
</div>
</div>
<br>
<br>
<br>
<?= $this->render('//layouts/_footer') ?>