Controls and Filters with custom remote datasource

173 views
Skip to first unread message

Geneocide

unread,
May 19, 2012, 11:51:06 PM5/19/12
to Google Visualization API
First, I apologize for being a newb, but I am.

I have a mysql database that I've been querying with PHP and drawing
charts from the results after I format the results to JSON. It looks
something like this....

function drawYearlyChart() {
var jsonData = $.ajax({
url: "getYearlyData.php",
dataType:"json",
async: false
}).responseText;

//create data table out of JSON data from server
var data = new google.visualization.DataTable(jsonData);

//instantiate and draw chart
var chart = new
google.visualization.SteppedAreaChart(document.getElementById('yearlyChart'));
chart.draw(data);
}
Is there a way to use controls with this sort of data source? I've
been looking at the documentation and I can't see a way to do it. When
I play around with what I got I don't get any helpful errors or
anything. Tips would be appreciated.

ChartMan

unread,
May 20, 2012, 1:56:13 AM5/20/12
to google-visua...@googlegroups.com

You can definitely use controls regardless of where or how your data is queried to the client.
what type of data (column types) are you using and what is failing?

--
You received this message because you are subscribed to the Google Groups "Google Visualization API" group.
To post to this group, send email to google-visua...@googlegroups.com.
To unsubscribe from this group, send email to google-visualizati...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/google-visualization-api?hl=en.

Geneocide

unread,
May 20, 2012, 2:13:48 AM5/20/12
to Google Visualization API
I just have a 2 column bar graph type thing. My main problem I think
stems from the example having a chart wrapper and I dunno how to do my
ajax call from within a wrapper. I've tried various things like they
do in this demo but I must be missing something. My getYearlyData.php
never even gets called. If there is an example of a control on a chart
that uses the jsonData = $.ajax({...}) format that would be most
helpful.

Or is there a different way of adding controls, w/o the wrapper?

On May 19, 10:56 pm, ChartMan <chart...@google.com> wrote:
> You can definitely use controls regardless of where or how your data is
> queried to the client.
> what type of data (column types) are you using and what is failing?

Geneocide

unread,
May 20, 2012, 2:15:22 AM5/20/12
to Google Visualization API
sorry post was breaking. Here's the link to the demo I tried to post.
https://code.google.com/apis/ajax/playground/?type=visualization#chartwrapper_with_remote_data

Also, the data is just strings and numbers

On May 19, 10:56 pm, ChartMan <chart...@google.com> wrote:
> You can definitely use controls regardless of where or how your data is
> queried to the client.
> what type of data (column types) are you using and what is failing?

ChartMan

unread,
May 20, 2012, 3:16:49 AM5/20/12
to google-visua...@googlegroups.com
The ChartWrapper supports Charts data source URLs - https://developers.google.com/chart/interactive/docs/queries
If you can't make your data available via a URL then you can fetch the data to your client and create a google.visualization.DataTable.
Once you have the data table you can create a google.visualization.ChartWrapper and assign it's "dataTable" field. 
Controls would now accept your ChartWrapper and should operate normally.

HTH
ChartMan

Geneocide

unread,
May 20, 2012, 11:52:15 AM5/20/12
to Google Visualization API
yay. I got it to work... somehow. Unfortunately I now realize it's not
going to do exactly what I want. If I have a column chart with 3 sets
of data in each column, can I get the picker to let me pick of those
3?

Like, say I have year 2000 to 2010 and each year I have the sale
figures of Bill, Joe and Sally. I want the picker to let me pick if I
show all 3 people, or just 2 or 1, not whether I show all 10 years or
just some of them.

Is there a relatively easy way to do this?

On May 20, 12:16 am, ChartMan <chart...@google.com> wrote:
> The ChartWrapper supports Charts data source URLs -https://developers.google.com/chart/interactive/docs/queries
> If you can't make your data available via a URL then you can fetch the data
> to your client and create a google.visualization.DataTable.
> Once you have the data table you can create a
> google.visualization.ChartWrapper and assign it's "dataTable" field.
> Controls would now accept your ChartWrapper and should operate normally.
>
> HTH
> ChartMan
>
>
>
>
>
>
>
> On Sun, May 20, 2012 at 9:15 AM, Geneocide <theg...@gmail.com> wrote:
> > sorry post was breaking. Here's the link to the demo I tried to post.
>
> >https://code.google.com/apis/ajax/playground/?type=visualization#char...

ChartMan

unread,
May 20, 2012, 3:51:41 PM5/20/12
to google-visua...@googlegroups.com
If I understand what you are asking then NO, there is no way to do this in the API.
However you can use a very simple drop down (<select>) which allows the user
to select which column to use.

HTH
ChartMan

asgallant

unread,
May 21, 2012, 9:55:24 AM5/21/12
to google-visua...@googlegroups.com
You can create standard HTML checkboxes, selectboxes, or whatever you like and attach event handlers to them to choose which columns to draw.  If you like the look of the built-in selectors, I wrote a hack that turns a category filter into a column filter: http://jsfiddle.net/asgallant/WaUu2/

You'll need all of the code there (including the HTML at the top).  Replace the "data" DataTable with your DataTable and the "chart" ChartWrapper with your ChartWrapper.
> > > > To unsubscribe from this group, send email to
> > > > 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
> > To unsubscribe from this group, send email to
Reply all
Reply to author
Forward
0 new messages