[FX.php List] jquery/gChart help

Gjermund Gusland Thorsen ggt667 at gmail.com
Fri Jan 9 16:17:23 MST 2009


In order to help you it would be very nice to see the output of
---
echo "<pre>";
print_r ($chart);
echo "</pre>";
---
However I believe this would bring a solution to your confusion
---
foreach( $wine_result['data'] as $wine_row_key=>$wine_row ) {
        $tmp[] = $wine_row['appellation'];
        $tmp[] = $wine_row['htmlcolor'];
        $tmp[] = $wine_row['qty'];
        $line[] = implode( ',', $tmp );
        unset( $tmp );
}
$chart = implode( "\n", line );
---
ggt


2009/1/9 david weiner <1265 at lucerneblvd.org>:
> Thanks Gjermund and Steve,
> I can see how this should be working, but there's a small gap in my brain
> between what I have and what I need.
> Using Gjermund's sample code I'm able to pull my data as comma separated
> values, but it's printing as "Array,Array,Array" and then if I add [0] to my
> data field I get a single value instead of an array.
>
> The code below shows what I have so far with the sample chart data below.
> The goal is to get my values into the text field box which will get me a
> proof of concept and I can work out the design from there.
>
> Any help would be great, thanks!
> David
>
> <!-- Code Sample -->
> <?php require_once('Connections/wine.php'); ?>
> <?php
> $wine_find = clone($wine);
> $wine_find->layout = 'web';
> $wine_findCriterions = array('wineID'=>'='.'*',);
> foreach($wine_findCriterions as $key=>$value) {
>    $wine_find->AddDBParam($key,$value);
> }
>
> $wine_result = $wine_find->FMFind();
> $wine_row = current($wine_result['data']);
> $wine_row_key = key($wine_result['data']);
>  ?>
> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
> "http://www.w3.org/TR/html4/loose.dtd">
> <html>
> <head>
> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
> <title>Untitled Document</title>
> <script type="text/javascript" src="js/jquery-1.2.6.min.js"></script>
> <script type="text/javascript" src="js/jquery.gchart.min.js"></script>
> <script type="text/javascript">
> $(function() {
> $('#csvChart').gchart({type: 'line',
>    dataLabels: ['2002', '2004', '2005', '2006'], legend: 'right'});
>
> $('#csvLoad').click(function() {
>    $('#csvChart').gchart('change',
>        {series: $.gchart.seriesFromCsv($('#csvSource').val())});
> });
>
> });;
> </script>
> </head>
>
> <body>
> <p>
>  <?php foreach($wine_result['data'] as $wine_row_key=>$wine_row){
>
>        $tmp[] = $wine_row['appellation'];
>        $tmp[] = $wine_row['htmlcolor'];
>        $tmp[] = $wine_row['qty'];
>        $chart[] = implode( ',', $tmp );
>        unset( $tmp );
> }
>  ?>
> <?php
> echo "<pre>";
> print_r ($chart);
> echo "</pre>";
> ?></p>
>
>                <p><span class="demoLabel">Load CSV:</span>
>                        <button id="csvLoad">Load</button></p>
>                <p><span class="demoLabel">&nbsp;</span>
>                        <textarea id="csvSource" rows="5"
> cols="50">label,color,y1,y2,y3,y4
> IE,ff0000,95.97, 91.80, 88.16, 86.64
> Netscape,00ff00,3.39, 2.83, 1.61, 0.00
> Firefox,0000ff,0.00, 4.06, 8.13, 9.95</textarea></p>
>                <div id="csvChart" style="width: 450px; height: 300px;
> margin-left: 15em;"></div>
>
> </body>
> </html>
>
> <!-- Code Sample End -->
>
>
> On Jan 9, 2009, at 12:01 AM, Gjermund Gusland Thorsen wrote:
>
>> foreach( $r['data'] as $k => $v ) {
>>        $tmp[] = $v['label'];
>>        $tmp[] = $v['color'];
>>        $tmp[] = $v['y1'];
>>        $chart = implode( ',', $tmp );
>>        unset( $tmp );
>> }
>>
>> $chart should now contain something similar to
>> ---
>> burgundy,ff0000,2
>> bourdeaux,00ff00,3
>> cabernet,0000ff,5
>> ---
>> asuming these are field names: label,color,y1 and you did a reasonable
>> FMFind prior to the foreach.
>>
>> ggt667
>>
>> 2009/1/9 Steve Winter <steve at bluecrocodile.co.nz>:
>>>
>>> Hi David,
>>> I've never used gChart before, but I'm going to take a punt at what
>>> you're
>>> trying to do, and make a few assumptions about the structure of your
>>> database and the labels that you want...
>>> I presume in FM you have a table which looks something like this;
>>> label   quantity
>>> burgundy 2
>>> bordeaux 3
>>> cabernet 5
>>> If the labels in FM are the same as the labels that you want to put on
>>> the
>>> chart, then I'd suggest adding another field to your database and storing
>>> the colour in there as well, so extend the above table,
>>> label   quantity colour
>>> burgundy 2   ff00ff
>>> bordeaux 3   00ffff
>>> cabernet 5   0000ff
>>> Then you can do an FX FindAll, and a simple foreach loop to parse the
>>> data
>>> from the query into whatever format the gChart engine requires (writing
>>> it
>>> an xml file? javascript array...?)
>>> If any of my assumptions above aren't correct, then let us know and we
>>> can
>>> add more information...
>>> Hope this helps
>>> Cheers
>>> Steve
>>> On 8 Jan 2009, at 22:56, david weiner wrote:
>>>
>>> Hi,
>>> Does anyone on the list have experience getting data formatted correctly
>>> from Filemaker to FX and picked up by the gChart jQuery plugin?
>>> I've got it all but working and am missing just how to format my data so
>>> it
>>> can be successfully parsed by the Google Chart API.
>>> What I've got is a qty listing of wine that I'm trying to get into the
>>> requested format of:
>>> label,color,y1 burgundy,ff0000,2 bourdeaux,00ff00,3 cabernet,0000ff,5
>>> (where 2,3 and 5 are qty's stored in the db)
>>> All help is appreciated, and if there's a suggestion for a better way to
>>> bring data into charts please let me know.
>>> Thanks,
>>> David
>>> _______________________________________________
>>> FX.php_List mailing list
>>> FX.php_List at mail.iviking.org
>>> http://www.iviking.org/mailman/listinfo/fx.php_list
>>>
>>>
>>> _______________________________________________
>>> FX.php_List mailing list
>>> FX.php_List at mail.iviking.org
>>> http://www.iviking.org/mailman/listinfo/fx.php_list
>>>
>>>
>> _______________________________________________
>> FX.php_List mailing list
>> FX.php_List at mail.iviking.org
>> http://www.iviking.org/mailman/listinfo/fx.php_list
>
> _______________________________________________
> FX.php_List mailing list
> FX.php_List at mail.iviking.org
> http://www.iviking.org/mailman/listinfo/fx.php_list
>


More information about the FX.php_List mailing list