Whoops! Drew is right, I got it sideways.
On Wed, Jul 11, 2012 at 12:22 PM, asgallant <[email protected]>wrote:
> That won't work to generate the same chart - you need to pivot that array.
> Something like this:
>
> $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; ?>);
>
> Note that I wrote up the PHP without testing it, so it is quite possible
> that there are minor syntax errors or typos in it, but the essence of what
> you need is there.
>
> On Wednesday, July 11, 2012 9:09:04 AM UTC-4, Allen "Prisoner" Firstenberg
> wrote:
>>
>> Given your spreadsheet, you treat rows 11 through 13 as an array of
>> arrays. Each row is an array with the values in that row. You get something
>> like this in JSON:
>>
>> [
>> ['Matn', 'value1', 'value2', 'value3', 'value4'].
>> ['blabla', 100, 88, 84, 16],
>> ['blabla 2', 100, 78, 34, 6]
>> ]
>>
>> This can be fed directly into arrayToDataTable() on the javascript side
>> to generate the same table shown in your chart.
>>
>>
>> On Wed, Jul 11, 2012 at 8:25 AM, Adam Hardarson <[email protected]
>> > wrote:
>>
>>> Thanks for the reply!
>>>
>>> I've looked at how the data should be formatted but I just cant wrap my
>>> head around on how to accomplish it!
>>>
>>> To better illustrate what I'm going for I put in a spreadsheet:
>>> https://docs.google.com/**spreadsheet/ccc?key=**
>>> 0AsRWz3wVoWuLdGwtckVHS2k0a09Kb**kZXc1VCUGR6VFE<https://docs.google.com/spreadsheet/ccc?key=0AsRWz3wVoWuLdGwtckVHS2k0a09KbkZXc1VCUGR6VFE>
>>>
>>>
>>> This is my code to get the approriate values from the two dropdowns
>>> ($first and $second):
>>> $result124 = mysql_query("SELECT Matningsnamn AS Matning,
>>> Value1,
>>> Value2 ,
>>> Value3 ,
>>> Value4
>>> FROM myDB WHERE Id ='$first' OR Id ='$second'");
>>> $rows = array();
>>> while($r = mysql_fetch_assoc($result124)) {
>>> $rows[] = $r;
>>> }
>>> $gn = json_encode($rows);
>>>
>>> which results in:
>>> [{"Matning":"blabla","Value1":**"100","value2":"88","value3":"**
>>> 84","value4":"16"},
>>> {"Matning":"blabla 2","Value1":"100","value2":"**
>>> 78","value3":"34","value4":"6}**]
>>>
>>> I didn't really understand your example, this is all so new to me... :-/
>>>
>>> If you look in the spreadsheet on how the graph looks, do you have any
>>> ideas on how to make it look like that or further reading suggestions?!
>>>
>>> Thank you all for engaging in my silly problem :)
>>> Adam
>>>
>>>
>>> Den tisdagen den 10:e juli 2012 kl. 21:17:54 UTC+2 skrev Allen
>>> "Prisoner" Firstenberg:
>>>
>>>> Adam,
>>>>
>>>> It depends what you want to do, but the easiest solution would be to
>>>> target a data format specified at https://developers.google.**c**
>>>> om/chart/interactive/docs/**data**tables_dataviews<https://developers.google.com/chart/interactive/docs/datatables_dataviews>
>>>> In particular, you might want to look at the arrays that can be fed
>>>> directly into arrayToDataTable() - the example on that page should show
>>>> what it needs to look like.
>>>>
>>>> What I've done in this case is to take the associative array in PHP and
>>>> iterate over all the keys. If the key is a number (tested by PHP's
>>>> is_numeric() function), then throw it out. Otherwise, create a new array
>>>> row with values being the key and value from the associative array and add
>>>> this to the array to return.
>>>>
>>>> Your needs may vary, but this has worked for the things I've tried to
>>>> do.
>>>>
>>>> Allen
>>>>
>>>>
>>>> --
>>> 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/-**/x5HHlSpyvO0J<https://groups.google.com/d/msg/google-visualization-api/-/x5HHlSpyvO0J>
>>> .
>>>
>>> To post to this group, send email to google-visualization-api@**
>>> googlegroups.com <[email protected]>.
>>> To unsubscribe from this group, send email to google-visualization-api+*
>>> *[email protected]<google-visualization-api%[email protected]>
>>> .
>>> For more options, visit this group at http://groups.google.com/**
>>> group/google-visualization-**api?hl=en<http://groups.google.com/group/google-visualization-api?hl=en>
>>> .
>>>
>>
>> --
> 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/-/MU-Ir1cx-B8J.
>
> 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.
>
--
You received this message because you are subscribed to the Google Groups
"Google Visualization API" group.
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.