sql server - Combo google chart with php from mssql -


i'm requiring advices on project i'm trying feed "combo" google chart 1 php ms sql server database. chart view template

i have built following view provides me relevant data. i'll have later create serie of these charts each project (identified via 'projectuniqueid').

table view template

from documentation got far, understand have programmatically build following datatable

    var data = google.visualization.arraytodatatable([       ['week', 'hrs vse', 'hrs pii', 'hrs vdg', 'hrs pia', 'hrs tcis', 'forecast'  ],       ['2013-w20',  165,          938,         522,         998,        450,          614.6],       ['2013-w21',  135,          1120,        599,         1268,       288,          682],       ['2013-w22',  157,          1167,        587,         807,        397,          1200],       ['2013-w23',  139,          1110,        615,         968,        215,          2000],       ['2013-w24',  136,          691,         629,         1026,       366,          569.5]     ]); 

as part of page:

<script type="text/javascript" src="https://www.google.com/jsapi"></script> <script type="text/javascript">   google.load('visualization', '1', {packages: ['corechart']}); </script> <script type="text/javascript">   function drawvisualization() {     //raw data     var data = google.visualization.arraytodatatable([       ['week', 'hrs vse', 'hrs pii', 'hrs vdg', 'hrs pia', 'hrs tcis', 'forecast'  ],       ['2013-w20',  165,          938,         522,         998,        450,          614.6],       ['2013-w21',  135,          1120,        599,         1268,       288,          682],       ['2013-w22',  157,          1167,        587,         807,        397,          1200],       ['2013-w23',  139,          1110,        615,         968,        215,          2000],       ['2013-w24',  136,          691,         629,         1026,       366,          569.5]     ]);      var options = {       title : 'actuals vs forecast vlu project per cost-center',       vaxis: {title: ""},       //horizontal axis text vertical       haxis: {title: "", slantedtext:true, slantedtextangle:90},       seriestype: "bars",       series: {5: {type: "line"}},       isstacked: true     };      var chart = new google.visualization.combochart(document.getelementbyid('chart_div'));     chart.draw(data, options);   }   google.setonloadcallback(drawvisualization); </script> 

i first tried build datatable (which understand "assembly" of arrays), manually

1) building array of "column headers" (ccname)

2) building array of "row headers" (weekvalue)

3) querying each individual value (hoursvalue) specific weekvalue,ccname ...

finally never managed build required array , found documentation on json , how didn't manage implement in code.

<?php  $myserver = "xxxxxx"; $myuser = "reportuser"; $mypass = ""; $mydb = "hours";   //connection database $dbhandle = mssql_connect($myserver, $myuser, $mypass)   or die("couldn't connect sql server on $myserver");   //select database work $selected = mssql_select_db($mydb, $dbhandle)   or die("couldn't open database $mydb");   //declare sql statement query database $query = "select ccname, weekvalue, sum(hoursvalue) hoursvalue viewfunctionalhourskpi approval='actuals' , projectuniqueid=1286 group ccname, weekvalue";  //execute sql query , return records $result = mssql_query($query)   or die('an error occured: ' . mysql_error());  $resultarray = array();  while ($record = mssql_fetch_array($result))   {     //fill array     $resultarray[] = $record;   }                      //output in json format echo json_encode($resultarray);  //free result set memory mssql_free_result($result);  //close connection mssql_close($dbhandle);  ?> 

what guys advice? i'm open change format of data changing current view i've got in ms sql server, hardest bit me how transport data php js datatable (if way it).

thanks help!

i have output same chart data google charts (rewritten use example) :

<?php      //this output of sql statement     $resultarray = array(array("this"=>5, "is" =>3, "a"=>4, "test"=>1),             array("this"=>25, "is" =>23, "a"=>42, "test"=>12),             array("this"=>50, "is" =>30, "a"=>40, "test"=>10));       //we find keys use "headers"     $keys = array_keys($resultarray[0]);      //loop through each key adding needed marks     $tempdata = '';     foreach($keys $key){         $tempdata .= "'$key',";     }      //this removes last comma (though might not need to)     $data ="[".rtrim($tempdata,',')."], \n";      //more looping, marking , comma removal     //just through whole list of results     foreach($resultarray $r){         $tempdata = '';         foreach($r $val){             $tempdata .= "'$val',";         }         $data .= "[".rtrim($tempdata,',')."], \n";     }     $data = "[".rtrim($data,", \n")."]";      //echo result     echo $data;  ?> 

hope works you


Comments

Popular posts from this blog

Unable to remove the www from url on https using .htaccess -