jquery - Morris.js donut chart not displaying chart when getting data through Ajax from php script -
jquery - Morris.js donut chart not displaying chart when getting data through Ajax from php script -
i working on displaying info through morris.js donut chart. these info come mysql database through php , ajax.
the typical illustration type info displayed right in code working fine
morris.donut({ element: 'donut-example', data: [ { label: "download sales", value: 12 }, { label: "in-store sales", value: 30 }, { label: "mail-order sales", value: 20 }] });
however, when phone call info database, chart not displayed. moreover, firebug not show errors.
this output php:
[{label: "4 pares",value: "9"},{label: "3 pares",value: "9"},{label: "2 pares",value: "6"},{label: "5 pares",value: "3"},{label: "6 pares",value: "2"},{label: "1 par",value: "2"}]
actually, tried output copying within morris.donut(); function , worked fine!
and ajax code (which doesn't work @ all):
$.ajax({ url: "ajax/modas_pares.php", type: "post", data: {loteria: 'melate', limit: 20}, success : function (resp){ //alert(resp); morris.donut({ element: 'donut-example', data: resp }); }, error: function(jqxhr, textstatus, ex) { console.log(textstatus + "," + ex + "," + jqxhr.responsetext); } });
however, if have next code:
$.ajax({ url: "ajax/modas_pares.php", cache: false, type: "post", data: {loteria: 'melate', limit: 20}, //datatype: "json", timeout:3000, success : function (resp){ //var column_data = $.parsejson(resp); //alert(resp); morris.donut({ element: 'donut-example', data: [{label: "3 pares",value: "6"},{label: "4 pares",value: "5"},{label: "2 pares",value: "5"},{label: "5 pares",value: "3"},{label: "1 par",value: "1"},{label: "6 pares",value: "1"}] }); }, error: function(jqxhr, textstatus, ex) { console.log(textstatus + "," + ex + "," + jqxhr.responsetext); } });
it work, fine!!!
what don't that, if tried passing code through variable, not work!! :
$string='[{label: "4 pares",value: "9"},{label: "3 pares",value: "9"},{label: "2 pares",value: "6"},{label: "5 pares",value: "3"},{label: "6 pares",value: "2"},{label: "1 par",value: "2"}]'; ?>
and
$.ajax({ url: "ajax/modas_pares.php", cache: false, type: "post", data: {loteria: 'melate', limit: 20}, //datatype: "json", timeout:3000, success : function (resp){ //var column_data = $.parsejson(resp); //alert(resp); morris.donut({ element: 'donut-example', data: '<?php echo $string ?>' }); }, error: function(jqxhr, textstatus, ex) { console.log(textstatus + "," + ex + "," + jqxhr.responsetext); } });
it doesn't work :( if either php variable or php script through ajax :/
what missing? how can prepare this? why?????
el error que tienes es cuando armas el array. en la parte php debes armar de esta forma:
$resp = array( array('label' => '5 pares','value' => 4), array('label' => '3 pares','value' => 8) ); echo json_encode( $resp );
luego puedes usar:
$.ajax({ url: "ajax/modas_pares.php", type: "post", data: {loteria: 'melate', limit: 20}, datatype: "json", timeout:3000, success : function (resp){ morris.donut({ element: 'donut-example', data: resp }); }, error: function(jqxhr, textstatus, ex) { console.log(textstatus + "," + ex + "," + jqxhr.responsetext); } });
jquery ajax morris.js donut-chart
Comments
Post a Comment