dynamic - Populating amchart dynamically fetching data from mysql -


i trying fetch records mysql , render data via amchart, facing difficulty in doing so. have written following code not working. query works fine problem replacing static (placeholder) data results of query. please suggest.

{  $selectdata="select member_lhp, count( * )  'land_pattern' hh_basic_info group member_lhp"; $resdata=mysql_query($selectdata);  <script type="text/javascript">     var chart;     var chartdata = [         <?php             $count=0;             while($rowdata = mysql_fetch_assoc($resdata))             foreach($rowdata $rows){                 $type= $rows['member_lhp'];                 $lp=$rows['land_pattern'];                 if($count++ > 0) echo ',';         ?>         {             year: <?php echo $type;?>,             income: <?php echo $lp;?>         },         <?php } ?>     ];      amcharts.ready(function () {         // serial chart         chart = new amcharts.amserialchart();         chart.dataprovider = chartdata;         chart.categoryfield = "year";         // single line makes chart bar chart,          // try set false - bars turn columns                         chart.rotate = true;         // following 2 lines makes chart 3d         chart.depth3d = 20;         chart.angle = 30;          // axes         // category         var categoryaxis = chart.categoryaxis;         categoryaxis.gridposition = "start";         categoryaxis.axiscolor = "#dadada";         categoryaxis.fillalpha = 1;         categoryaxis.gridalpha = 0;         categoryaxis.fillcolor = "#fafafa";          // value         var valueaxis = new amcharts.valueaxis();         valueaxis.axiscolor = "#dadada";         valueaxis.title = "villagers - land holding pattern";         valueaxis.gridalpha = 0.1;         chart.addvalueaxis(valueaxis);          // graph         var graph = new amcharts.amgraph();         graph.title = "income";         graph.valuefield = "income";         graph.type = "column";         graph.balloontext = "land holding number in [[category]]:[[value]]";         graph.linealpha = 0;         graph.fillcolors = "#bf1c25";         graph.fillalphas = 1;         chart.addgraph(graph);          // write         chart.write("chartdiv");     }); </script> } 

at quick glance looks may have included comma after curly bracket. adding comma via php if count greater 0 have been introducing second, unnecessary 1 between each group of data.

you had following...

    {       year: <?php echo $type;?>,       income: <?php echo $lp;?>     }, 

try having instead...

    {       year: <?php echo $type;?>,       income: <?php echo $lp;?>     } 

Comments