Nuestro team de especialistas luego de ciertos días de trabajo y de recopilar de datos, hemos dado con la solución, esperamos que te sea útil para tu plan.
Ejemplo: chart.js: obtener datos de la base de datos usando mysql y php
Please place your php code into another file called api.php anduse $.ajax to get these data with JSON format. To convert data into JSON format data you should usejson_encode() php function.I have set sample example you can see here.
Please refer below code example:
api.php$arrLabels=array("January","February","March","April","May","June","July");$arrDatasets=array('label'=>"My First dataset",'fillColor'=>"rgba(220,220,220,0.2)",'strokeColor'=>"rgba(220,220,220,1)",'pointColor'=>"rgba(220,220,220,1)",'pointStrokeColor'=>"#fff",'pointHighlightFill'=>"#fff",'pointHighlightStroke'=>"rgba(220,220,220,1)",'data'=>array('28','48','40','19','86','27','90'));$arrReturn=array(array('labels'=>$arrLabels,'datasets'=>$arrDatasets));print(json_encode($arrReturn));
example.html
$.ajax(type:'POST',url:'api.php',success:function(data)
lineChartData = data;//alert(JSON.stringify(data));var myLine =newChart(document.getElementById("canvas").getContext("2d")).Line(lineChartData);var ctx = document.getElementById("canvas").getContext("2d");
window.myLine =newChart(ctx).Line(lineChartData,responsive:true););
Please note that you should pass value of randomScalingFactor() at api.php.
Please check and let me know if you require any further help.
Comentarios y calificaciones
Acuérdate de que tienes la opción de comentar si te fue útil.
¡Haz clic para puntuar esta entrada!
(Votos: 0 Promedio: 0)