Nice work! 

I am however still getting the  Table has no columns.× 

I copied the code from a google example but there is still something wrong! 

This is what the script looks like:
<script type="text/javascript" src="https://www.google.com/jsapi";></script>
    <script type="text/javascript">
      google.load("visualization", "1", {packages:["corechart"]});
      google.setOnLoadCallback(drawChart);
      function drawChart() {
        var data = new google.visualization.DataTable(<?php echo 
$dataTable; ?>);  

        var options = {
          title: 'MP'
        };

        var chart = new 
google.visualization.AreaChart(document.getElementById('chart_div'));
        chart.draw(data, options);
      }
    </script>
</head>

take care
Adam

Den onsdagen den 11:e juli 2012 kl. 22:41:05 UTC+2 skrev asgallant:
>
> I changed it up a bit to fit whatever column structure you like:
>
> $sqlCols = array(
> 'Matning',
> 'Top',
> 'In',
> 'Pre',
> 'Int'
> );
> $result124 = mysql_query("
> SELECT Matningsnamn AS Matning, 
> Top, 
> In, 
> Pre, 
> Int
> FROM myDB WHERE Id ='$first' OR Id ='$second'"
> );
> $rawRows = array();
> $cols = array();
> // set up domain column
> $cols[] = array(
> 'type' => 'string',
> 'label' => 'Foo (rename as you like)'
> );
> while($r = mysql_fetch_assoc($result124)) {
> $cols[] = array(
> 'type' => 'string',
> 'label' => $r[$sqlCols[0]]
> );
>     $rawRows[] = $r;
> }
>
> $outRows = array();
> for ($i = 1; $i < count($rawRows[0]); $i++) {
> $temp = array();
> $temp[0] = array('v' => $sqlCols[$i]);
> for ($j = 0; j < count($rawRows); j++) {
> if ($rawRows[$j]['Matning'] == $cols[1]['label']) {
> $temp[1] = array('v' => $rawRows[$j][$sqlCols[$i]]);
> }
> else if ($rawRows[$j]['Matning'] == $cols[2]['label']) {
> $temp[2] = array('v' => $rawRows[$j][$sqlCols[$i]]);
> }
> }
> $outRows[] = array('c' => $temp);
> }
>
> $dataTable = json_encode(array(
> 'cols' => $cols,
> 'rows' => $outRows
> ));
>
> //.... then in the javascript, use:
>
> var data = new google.visualization.DataTable(<?php echo $dataTable; ?>);
>   
>
> Make sure you are using a DataTable constructor and not the 
> arrayToDataTable method.  I tried out the JSON string you posted and it 
> works fine for me.
>
> On Wednesday, July 11, 2012 3:23:00 PM UTC-4, Adam Hardarson wrote:
>>
>> That solved that problem but now i get  Table has no columns.×  
>> if I print the json I get:
>>
>> {"cols":[{"type":"string","label":"Value 
>> #"},{"type":"string","label":"Test 1"},{"type":"string","label":"Test 2"}],
>>
>> "rows":[{"c":[{"v":"Value1"},{"v":"61"},{"v":"66"}]},{"c":[{"v":"Value2"},{"v":"90"},{"v":"83"}]},{"c":[{"v":"Value3"},{"v":"37"},{"v":"71"}]},{"c":[{"v":"Value4"},{"v":"48"},{"v":"84"}]}]}
>>  
>>
>> For this to work I changed my original code like this:
>>
>> $result124 = mysql_query("
>> SELECT Matningsnamn AS Matning, 
>> Top AS Value1, 
>> In AS Value2 , 
>> Pre AS Value3 , 
>> Int ASValue4   
>> FROM myDB WHERE Id ='$first' OR Id ='$second'"
>>
>> So I realize that I wrote that the "columnnames" were Value1, Value2, 
>> Value3 and Value 4 but this was just to illustrate. The column names is 
>> totally different from that, will that screw the code up or is it easy to 
>> edit to display the real names? Or even better is it possible to enter the 
>>  labels manually and just getting the values from the database? So that 
>> when I choose a new row from the dropdown only the values changes?
>>
>> Sorry for confusing everything!!!!
>>
>> Adam
>>
>> Den onsdagen den 11:e juli 2012 kl. 20:30:18 UTC+2 skrev asgallant:
>>>
>>> I forgot the $'s in front of the i's there, try this:
>>>
>>> for ($i = 1; $i < count($rawRows[0]); $i++) { 
>>>
>>> On Wednesday, July 11, 2012 2:04:09 PM UTC-4, Adam Hardarson wrote:
>>>>
>>>> Hi again, thank you so much for your assistance!
>>>>
>>>> However it's not working so I the page for syntax error and got a Parse 
>>>> error: syntax error, unexpected T_INC, expecting ')' in test.php on line 
>>>> 37.
>>>>
>>>> That's where the for loop starts... I can't see what the problem might 
>>>> be?!
>>>>
>>>>
>>>>> $result124 = mysql_query("
>>>>> SELECT Matningsnamn AS Matning, 
>>>>> Value1, 
>>>>> Value2 , 
>>>>> Value3 , 
>>>>> Value4   
>>>>> FROM myDB WHERE Id ='$first' OR Id ='$second'"
>>>>> );
>>>>> $rawRows = array();
>>>>> $cols = array();
>>>>> // set up domain column
>>>>> $cols[] = array(
>>>>> 'type' => 'string',
>>>>> 'label' => 'Value #'
>>>>> );
>>>>> while($r = mysql_fetch_assoc($result124)) {
>>>>> $cols[] = array(
>>>>> 'type' => 'string',
>>>>> 'label' => $r['Matning']
>>>>> );
>>>>>     $rawRows[] = $r;
>>>>> }
>>>>>
>>>>> $outRows = array();
>>>>> for ($i = 1; i < count($rawRows[0]); i++) {
>>>>> $temp = array();
>>>>> $temp[0] = array('v' => "Value$i");
>>>>> for ($j = 0; j < count($rawRows); j++) {
>>>>> if ($rawRows[$j]['Matning'] == $cols[1]['label']) {
>>>>> $temp[1] = array('v' => $rawRows[$j]["Value$i"]);
>>>>> }
>>>>> else if ($rawRows[$j]['Matning'] == $cols[2]['label']) {
>>>>> $temp[2] = array('v' => $rawRows[$j]["Value$i"]);
>>>>> }
>>>>> }
>>>>> $outRows[] = array('c' => $temp);
>>>>> }
>>>>>
>>>>> $dataTable = json_encode(array(
>>>>> 'cols' => $cols,
>>>>> 'rows' => $outRows
>>>>> ));
>>>>>
>>>>> You can then output this into the DataTable constructor:
>>>>>
>>>>> var data = new google.visualization.DataTable(<?php echo $dataTable; 
>>>>> ?>); 
>>>>>
>>>>
>>>> Seeing the end of the tunnel... :)
>>>>
>>>> Adam 
>>>>
>>>
>> Den onsdagen den 11:e juli 2012 kl. 20:30:18 UTC+2 skrev asgallant:
>>>
>>> I forgot the $'s in front of the i's there, try this:
>>>
>>> for ($i = 1; $i < count($rawRows[0]); $i++) { 
>>>
>>> On Wednesday, July 11, 2012 2:04:09 PM UTC-4, Adam Hardarson wrote:
>>>>
>>>> Hi again, thank you so much for your assistance!
>>>>
>>>> However it's not working so I the page for syntax error and got a Parse 
>>>> error: syntax error, unexpected T_INC, expecting ')' in test.php on line 
>>>> 37.
>>>>
>>>> That's where the for loop starts... I can't see what the problem might 
>>>> be?!
>>>>
>>>>
>>>>> $result124 = mysql_query("
>>>>> SELECT Matningsnamn AS Matning, 
>>>>> Value1, 
>>>>> Value2 , 
>>>>> Value3 , 
>>>>> Value4   
>>>>> FROM myDB WHERE Id ='$first' OR Id ='$second'"
>>>>> );
>>>>> $rawRows = array();
>>>>> $cols = array();
>>>>> // set up domain column
>>>>> $cols[] = array(
>>>>> 'type' => 'string',
>>>>> 'label' => 'Value #'
>>>>> );
>>>>> while($r = mysql_fetch_assoc($result124)) {
>>>>> $cols[] = array(
>>>>> 'type' => 'string',
>>>>> 'label' => $r['Matning']
>>>>> );
>>>>>     $rawRows[] = $r;
>>>>> }
>>>>>
>>>>> $outRows = array();
>>>>> for ($i = 1; i < count($rawRows[0]); i++) {
>>>>> $temp = array();
>>>>> $temp[0] = array('v' => "Value$i");
>>>>> for ($j = 0; j < count($rawRows); j++) {
>>>>> if ($rawRows[$j]['Matning'] == $cols[1]['label']) {
>>>>> $temp[1] = array('v' => $rawRows[$j]["Value$i"]);
>>>>> }
>>>>> else if ($rawRows[$j]['Matning'] == $cols[2]['label']) {
>>>>> $temp[2] = array('v' => $rawRows[$j]["Value$i"]);
>>>>> }
>>>>> }
>>>>> $outRows[] = array('c' => $temp);
>>>>> }
>>>>>
>>>>> $dataTable = json_encode(array(
>>>>> 'cols' => $cols,
>>>>> 'rows' => $outRows
>>>>> ));
>>>>>
>>>>> You can then output this into the DataTable constructor:
>>>>>
>>>>> var data = new google.visualization.DataTable(<?php echo $dataTable; 
>>>>> ?>); 
>>>>>
>>>>
>>>> Seeing the end of the tunnel... :)
>>>>
>>>> Adam 
>>>>
>>>

-- 
You received this message because you are subscribed to the Google Groups 
"Google Visualization API" group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/google-visualization-api/-/Bs13OHjimRUJ.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/google-visualization-api?hl=en.

Reply via email to