Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public function actionGrafico(){
- $pacientes = Paciente::model()->findAll();
- $listaPacientes = array();
- //print_r($pacientes);die();
- foreach ($pacientes as $key => $value) {
- $model = $value;//->attributes;
- $nombreCompletoPaciente = $model->nombrePaciente." ".$model->apellidoPaciente;
- $listaPacientes[$model->idpaciente] = $nombreCompletoPaciente;
- }
- $this->render('grafico',array(
- 'listaPacientes'=>$listaPacientes,
- ));
- }
- <div id="wrapPrincipal">
- <div id="formUsuario">
- <?php
- $model = new Paciente;
- echo CHtml::label('Paciente',"Paciente");
- echo CHtml::dropDownList('Paciente[idPaciente]',"",$listaPacientes,array(
- 'id'=>'selectPaciente'
- ));
- ?>
- </div>
- <br><br>
- <br><br><br>
- <div id="wrapGrafico">
- <canvas id="grafico" class=""></canvas>
- </div>
- </div>
- <?php
- Yii::app()->getClientScript()->registerScriptFile(Yii::app()->theme->baseUrl.'/js/Chart.bundle.js');
- ?>
- <script>
- var xdata=["Enero", "Febrero", "Marzo", "Abril", "Mayo", "Junio","Julio","Agosto","Septiembre","Octubre"];
- var ydata=[3000, 3000, 3000, 3000, 3000, 3000, 3000, 3000, 3000, 3000];
- var grafico;
- $(document).ready(function(){
- var ctx = $("#grafico");
- grafico = new Chart(ctx,{
- type: 'bar',
- data: {
- labels: xdata,
- datasets:[{
- label: "Utilidad",
- data: ydata,
- borderWidth: 2,
- borderColor: "rgba(75,192,192,1)",
- fill: false,
- borderWidth: 4,
- }
- ]
- },
- options: {
- //responsive: true,
- maintainAspectRatio: true,
- scaleShowVerticalLines: false,
- scaleShowHorizontalLines: false,
- scaleStartValue : 0,
- scales: {
- xAxes : [ {
- gridLines : {
- display : false
- }
- } ],
- yAxes: [{
- gridLines : {
- display : false
- },
- ticks: {
- suggestedMin: 20,
- callback: function(value, index, values) {
- return value.toString().replace(/(\d)(?=(\d{3})+(?!\d))/g, "$1,")
- },
- }
- }]
- }
- },
- });
- dibujarGrafico();
- setInterval(function(){
- dibujarGrafico();
- },1000)
- });
- function reverse(array){
- var new_array = [];
- for(var i = 0; i< array.length; i++){
- new_array[i] = array[array.length -i - 1];
- }
- return new_array;
- }
- var idPaciente;
- function dibujarGrafico(){
- idPaciente = $('#selectPaciente').val();
- console.log(idPaciente)
- $.ajax({
- type: 'GET',
- url: '<?php echo Yii::app()->createUrl('site/tempsPaciente');?>',
- data: 'idPaciente='+idPaciente,
- success: function(data){
- var json = JSON.parse(data);
- if ( json["estado"] == 1){
- var valores = json["valores"];
- xdata=[];
- ydata=[];
- for (var i = 0; i < valores.length; i++) {
- ydata.push(Number(valores[i]["valor"])*1);
- xdata.push(valores[i]["fecha"]);
- //console.log("bitch"+valores[i]["valor"]);
- //console.log("bitch"+valores[i]["fecha"]);
- }
- console.log(ydata);
- console.log(xdata);
- console.log("FUCKKKK");
- //console.log(valores);
- grafico.data.datasets[0].data = reverse(ydata);
- grafico.data.labels = reverse(xdata);
- grafico.update();
- }else{
- var canvas = document.getElementById("grafico");
- canvasMensajeVacio(canvas);
- }
- },
- });
- }
- function limpiarCanvas(canvas){
- var contexto = canvas.getContext("2d");
- contexto.clearRect(0, 0, canvas.width, canvas.height);
- }
- function canvasMensajeVacio(canvas){
- limpiarCanvas(canvas);
- var contexto = canvas.getContext("2d");
- contexto.font = "30px Arial";
- contexto.fillText("JSON ESTADO 0",10,50);
- }
- </script>
- //////
- public function actionTempsPaciente(){
- $idPaciente = $_GET["idPaciente"];
- $idSensor = 1; //temp
- $criteria = new CDbCriteria();
- $criteria->addCondition("paciente_idpaciente =:idpaciente");
- $criteria->addCondition("sensor_idSensor =:idSensor");
- $criteria->params = array(
- ':idpaciente' => $idPaciente,
- ':idSensor'=>$idSensor);
- $criteria->limit = 10;
- $criteria->order = "fecha DESC";
- $Valores = Valores::model()->findAll($criteria);
- $json = array();
- $valoresJson = array();
- if ($Valores){
- foreach ($Valores as $key => $value) {
- $valoresJson[] = $value->attributes;
- }
- $json["estado"] = 1;
- $json["mensaje"] = "OK";
- $json["valores"] = $valoresJson;
- }else{
- $json["estado"] = 0;
- $json["mensaje"] = "No hay valores";
- }
- echo json_encode($json);
- }
Advertisement
Add Comment
Please, Sign In to add comment