Hello I need to add chart in my view
I still confusing, there are many chart example in internet but using javascript, and a little using table as chart base value...
I need your help to input my value on database and table to my chart
here my View:
<table><?php if($query): foreach($query as $post) ?>
<tr>
<th> Number </th> <th> Jenis </th> <th> Hasil </th>
</tr>
<tr>
<td> 01 </td> <td> <? echo $post->jenis1; </td> <td> <? echo $post->hasil1; ?> </td>
<td> 02 </td> <td> <? echo $post->jenis2; </td> <td> <? echo $post->hasil2; ?> </td>
....etc
</tr><?php endforeach;?>
</table><?php endif ?>
Here My Javascript script for graphic on below
<script lang="javascript" type="text/javascript">
$(document).ready(function () {
$('#jqChart').jqChart({
title: { text: 'Grafik Masalah Individu' },
axes: [
{
location: 'left',
minimum: 0,
maximum: 100,
interval: 5
}
],
series: [
{
type: 'column',
data: [['Kesehatan',3], ['Ekonomi', 14], ['Keluarga', 65], ['Agama & Moral', 85 ], ['Pribadi', 76], ['Hubungan Sosial', 43]]
} /* I want to insert my database value there */
]
});
});
</script>
I hope this help
<script lang="javascript" type="text/javascript">
$(document).ready(function () {
$('#jqChart').jqChart({
title: { text: 'Your graph name' },
axes: [
{
location: 'left',
minimum: 0,
maximum: 100,
interval: 5
}
],
series: [
{
type: 'column',
data: [[<? echo $post->jenis1; ?>], <? echo $post->hasil1; ?>], [<? echo $post->jenis2; ?>], <? echo $post->hasil2; ?>], ...etc]
}
]
});
});
</script>
Related
I would like to see if you can help me with this. I want to display an image already saved in my database as a blob type in my datatable in Laravel 6.
my code clients.blade.php
<th>#</th>
<th>Nombre</th>
<th>Observacion</th>
<th>Estado</th>
<th>Grabacion</th>
<th width="150px">Imagen</th>
<th>Fecha</th>
<th>Acciones</th>
</tr>
</thead>
<tbody>{{--
#foreach ($client as $key => $value)
<tr>
<td>{{($key+1)}}</td>
<td>{{($value["titulo"])}}</td>
<td>{{($value["observacion"])}}</td>
<td>{{($value["estado"])}}</td>
<td>{{($value["grabacion"])}}</td>
<td>
<img src="{{($value["lugar_imagen"])}}" class="img-fluid" >
</td>
...
code js(datatable).
columns: [
{
data: 'id',
name: 'id'
},
{
data: 'titulo',
name: 'titulo'
},
{
data: 'observacion',
name: 'observacion'
},
{
data: 'estado',
name: 'estado'
},
{
data: 'grabacion',
name: 'grabacion'
},
//columna mostrar imagen blob
{
data: 'lugar_imagen',
name: 'lugar_imagen',
render: function (data, type, row, meta) {
var imgsrc = 'data:image/png;base64,' + data;
return '<img class="img-responsive" src="' + imgsrc +'" " height="100px" width="100px">';
}
},
orderable: false
},
...
attentive to your comments. Thank
You need in the td only put the base64 blob.
<td> <img src="{{($value["lugar_imagen"])}}" class="img-fluid" ></td>
is only
<td> {{($value["lugar_imagen"])}} </td>
I have a problem in rendering a view in Yii2 that has been troubling me for a couple of days.The rendering was working just fine until one morning it decided not to work. The view displays raw HTML code instead of the user interface.
Here is the code for my controller that renders the view
if ($fails == TRUE)
{
Yii::$app->session->setFlash('error', 'The following records failed validation, kindly update and submit');
return $this->render('failedvalidation',['fails' => $fails,]);
} else {
Yii::$app->session->setFlash('success', 'File uploaded successfully,waiting approval');
return $this->redirect(Yii::$app->request->referrer);
}
Below is the code for my view file(failedvalidation.php)
<?php
use yii\helpers\Html;
use yii\bootstrap\Modal;
use yii\helpers\Url;
?>
<div class="bulkpayments-view">
<div class="box box-default">
<div class="table-responsive">
<table class="display nowrap" id="example1">
<thead>
<tr>
<th>Ref No</th>
<th>Full Names</th>
<th>Id No</th>
<th>Credit Account</th>
<th>Amount</th>
<th>Narration</th>
<th>Action</th>
</tr>
</thead>
<tbody>
<?php foreach($fails as $data) {?>
<tr class="gradeX">
<td><?= $data['BENEFICIARYREFNO'];?></td>
<td><?= $data['BENEFICIARYFULLNAMES'];?></td>
<td><?= $data['IDNO'];?></td>
<td><?= $data['TOACCOUNT'];?></td>
<td><?= $data['AMOUNT'];?></td>
<td><?= $data['NARRATION'];?></td>
<td><?= Html::button('<i class="fa fa-pencil"></i>
Update', ['value' => Url::to(['update-failed-validation', 'id' =>
$data['ID'],'transid' => $data['TRANSACTIONID']]), 'class' => 'button btn
btn-primary btn-xs']) ?></td>
</tr>
<?php }?>
</tbody>
</table>
</div>
</div>
</div>
<?php
Modal::begin([
'header' => '<h4>Update Record</h4>',
'id' => 'modal',
'size' => 'modal-lg',
'clientOptions' => ['backdrop' => 'static', 'keyboard' => false],
]);
echo '<div id="content"></div>';
Modal::end();
?>
<?php
$js = <<<JS
$('.button').click(function() {
if($('#modal').data('shown.bs.modal')) {
$('#modal').find('#content')
.html('<i class="fa fa-spinner fa-pulse fa-2x"></i>')
.load($(this).attr('value'));
}
else {
$('#modal').modal('show')
.find('#content')
.html('<i class="fa fa-spinner fa-pulse fa-2x"></i>')
.load($(this).attr('value'));
}
});
JS;
$this->registerJs($js);
?>
<?php
$script = <<< JS
$(function () {
$('#example1').DataTable( {
dom: 'Bfrtip',
buttons: [
{
//extend: 'excel',
exportOptions: {
orthogonal: 'sort'
}
}
],
columnDefs: [{
targets:[0,1,2],
render: function(data, type, row, meta){
if(type === 'sort'){
//data = ' ' + data ;
return "\u200C" + data ;
}
return data ;
}
}]
} );
});
JS;
$this->registerJs($script);
?>
<style>
.box{
padding:30px;
}
</style>
Screenshot of my view on browser and the raw HTML it displays:
Hi I had a similar situation and struggled for a few days. Finally I found that in one of my functions had this statement
\Yii::$app->response->format = \yii\web\Response::FORMAT_JSON;
So I had disabled this statement. It worked but I need to find a better solution. Hope this help
All together HTML with js work for custom filter. Here I am taking example of books with click filter when we click on subject name it filter
angular.module('testApp', []).controller('namesCtrl', function($scope) {
$scope.names = [{
name: 'Hindi'
},
{
name: 'Math'
},
{
name: 'English'
},
{
name: 'Science'
},
{
name: 'Computer'
},
{
name: 'History'
},
];
$scope.orderByMe = function(x) {
$scope.myOrderBy = x;
}
});
HTML Code
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.6.4/angular.min.js"></script>
<body>
<font size="3" color="red">
<p>Click the table headers to change the sorting order:</p>
</font>
<div ng-app="testApp" ng-controller="namesCtrl">
<table border="1" width="100%">
<tr>
<th ng-click="orderByMe('name')">Subject Name</th>
</tr>
<tr ng-repeat="x in names | orderBy:myOrderBy">
<td>{{x.name}}</td>
</tr>
</table>
</div>
I'm pretty new to angularjs.So,please kindly ignore if there are any errors.Here I have one dropdownlist within ng-repeat if I select the values in dropdownlist the corresponding Item code and the selected description from dropdownlist should pass to angularcontroller and I need to post it to the mvc controller
angular.module('myApp', [])
.controller('ctrl', ['$scope', '$http', '$rootScope',function ($scope, $http,$rootScope) {
$scope.values = [{
Code: 1,
Description: 'Apple'
}, {
Code: 2,
Description: 'Orange'
}, {
Code: 3,
Description: 'Mango'
}, {
COde: 4,
Description: 'Guva'
}
];
$scope.ddlrhs = '';
$scope.data = [{
Code: 1,
Description: 'Red'
}, {
Code: 2,
Description: 'Orange'
}, {
Code: 3,
Description: 'Yellow'
}, {
Code: 4,
Description: 'Green'
}
];
$scope.submit = function ()
{
$scope.list = [];
for (var i = 0; i < $scope.values.length; i++) {
var j = "";
$scope.list.push({
VALUE: $scope.values[i].Code,
Description: $scope.myForm.items[i].Description
})
}
$http({
method: "POST",
url: "/Controller/Save",
data:
$scope.list
})
}
}])
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.5/angular.min.js"></script>
<div id="dvcollection" ng-App="myApp" ng-controller="ctrl" >
<form name="myForm" >
<table id="tblcollections">
<thead>
<tr >
<th>ItemCode</th>
<th>ItemDesc</th>
<th>DropdownDesc</th>
<th>DropdownCode</th>
<th></th>
</tr>
</thead>
<tbody>
<tr ng-repeat="item in values">
<td><span>{{item.Code}}</span> </td>
<td>{{item.Description}}</td>
<td>
<select ng-model="myForm.items[$index]" ng-options=" element.Description for element in data ">
<option value="">Select </option>
</select>
</td>
<td><span>{{myForm.items[$index].Code}}</span></td>
</tr>
<tr>
<td></td>
<td></td>
<td></td>
<td></td>
<td>
<input type="button" value="save" ng-click="submit()"style="float:right;" >
</td>
</tr>
</tbody>
</table>
</form>
</div>
Hey May be this might be your expectation
<div ng-app="myApp" >
<div id="dvcollection" ng-controller="ctrl">
<form name="myForm">
<table id="tblcollections">
<thead>
<tr>
<th>ItemCode</th>
<th>ItemDesc</th>
<th>DropdownDesc</th>
<th>DropdownCode</th>
<th></th>
</tr>
</thead>
<tbody>
<tr ng-repeat="item in values">
<td><span>{{item.Code}}</span> </td>
<td>{{item.Description}}</td>
<td>
<select ng-model="itemssample" ng-options=" element.Description for element in data " ng-change="pushingelement(item.Code,itemssample.Code)">
<option value="">Select </option>
</select>
</td>
<td><span>{{myForm.items[$index].Code}}</span></td>
</tr>
<tr>
<td></td>
<td></td>
<td></td>
<td></td>
<td>
<input type="button" value="save" ng-click="submit()" style="float:right;">
</td>
</tr>
</tbody>
</table>
</form>
<div> This is written to ensure that mapping is stored or not. (Not necessary)
<p ng-repeat="item in list">
Mapping of {{$index}} element {{item.ItemCode}} -> {{item.ColorCode}}
</p>
</div>
</div>
</div>
Ensure that your MVC Controller should have a model as
public class MapperClass
{
public int ItemCode { get; set; }
public int ColorCode { get; set; }
}
SCRIPT
angular.module('myApp', [])
.controller('ctrl', ['$scope', '$http', '$rootScope', function ($scope, $http, $rootScope) {
$scope.list = [];
$scope.values = [
{ Code: 1, Description: 'Apple' },
{ Code: 2, Description: 'Orange' },
{ Code: 3, Description: 'Mango' },
{ Code: 4, Description: 'Guva' }
];
$scope.ddlrhs = '';
$scope.data = [
{ Code: 1, Description: 'Red' },
{ Code: 2, Description: 'Orange' },
{ Code: 3, Description: 'Yellow' },
{ Code: 4, Description: 'Green' }
];
$scope.pushingelement = function (itemCode, colorCode) {
var temp = { "ItemCode": itemCode, "ColorCode": colorCode };
$scope.list.push(temp);
console.log($scope.list);
}
$scope.submit = function () {
$http({
method: "POST",
url: "/Controller/Save",
data:
object:$scope.list
})
}
}
]);
TRY ONCE I HOPE IT HELPS YOU
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>get selected value from dropdownlist in angularjs</title>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.3.9/angular.min.js"></script>
<script type="text/javascript">
var app = angular.module('sampleapp', [])
app.controller('samplecontrol', function ($scope) {
$scope.sample = [{
id: '1',
name: 'Red'
}, {
id: '2',
name: 'Green'
}, {
id: '3',
name: 'Orange'
}, {
id: '4',
name: 'Yellow'
}];
});
</script>
</head>
<body data-ng-app="sampleapp" data-ng-controller="samplecontrol">
<form id="form1">
Select Name:
<select data-ng-model="ddlvalue">
<option value="">--Select--</option>
<option data-ng-repeat="t in sample" value="">{{t.name}}</option>
</select>
</form>
</body>
</html>
I am developing ASP.Net mvc 4 Application using EF .
This is Client/index.cshtml (Before Adding ExtJS)
#model IEnumerable<Proj.Client>
#{
ViewBag.Title = "Index";
}
<h2>Index</h2>
<p>
#Html.ActionLink("Create New", "Create")
</p>
<table>
<tr>
<th>
#Html.DisplayNameFor(model => model.Name_Clt)
</th>
<th>
#Html.DisplayNameFor(model => model.LName_Clt)
</th>
<th>
#Html.DisplayNameFor(model => model.Birthday_Clt)
</th>
<th></th>
</tr>
#foreach (var item in Model) {
<tr>
<td>
#Html.DisplayFor(modelItem => item.Name_Clt)
</td>
<td>
#Html.DisplayFor(modelItem => item.LName_Clt)
</td>
<td>
#Html.DisplayFor(modelItem => item.Birthday_Clt)
</td>
<td>
#Html.ActionLink("Edit", "Edit", new { id=item.ID_Client }) |
#Html.ActionLink("Details", "Details", new { id=item.ID_Client }) |
#Html.ActionLink("Delete", "Delete", new { id=item.ID_Client })
</td>
</tr>
}
</table>
I was following this blogpost , But I couldn't load data on it .
http://cincolabs.com/2012/04/10/asp-net-mvc-4-ext-js-4-gridpanel/
I created another ClientController .
public JsonResult GetUsers()
{
var entities = new Entities();
//What is important is to return the data as JSON.
return Json(entities.Clients.ToList(), JsonRequestBehavior.AllowGet);
}
Should I remplace this code .
public ActionResult Index()
{
var db = new Entities();
return View(db.Clients.ToList());
}
Another Question :
// Set up a model to use in our Store
Ext.define('Client', {
extend: 'Ext.data.Model',
fields: [
{ name: 'First_Name', type: 'string' },
{ name: 'Last_Name', type: 'string' },
{ name: 'Email', type: 'string' },
{ name: 'Date_Created', type: 'date', dateFormat: 'MS'}
]
});
var userStore = Ext.create('Ext.data.Store', {
model: 'Client',
proxy: {
type: 'ajax',
url: '/Examples/GetUsers',
reader: {
type: 'json',
root: 'users'
}
},
autoLoad: true
});
What does this mean "url: '/Examples/GetUsers'," !! Should I replace it in my case !!
Your first question is a bit vague. I never worked with Ext JS but from your posted code, it seems to me that it creates it own table using the GetUsers function. The first View you posted is an Index View that Visual Studio can automatically create that displays your data. If your Ext JS is creating the table, then I suggest you replace Index View with the appropriate code to call the table data. Then the method GetUsers should be renamed as Index.
Your question regarding /Examples/GetUsers should be the url to the controller method that saves your data (something like /Client/Save).