Avatar of msibley
msibley
Flag for United States of America asked on

Google Charts line graph from PHP arrays

I have a PHP script that processes data from a MySQL database. It basically is a series of amplitude values for a range of frequencies. The output winds up in 2 arrays, one holds the frequency (1, 1.5, 2, 2.5 ... 30) and the other holds the amplitude values (for example 2.5, 1.6, 9.5, etc.). What I'd like to do is output a simple line graph using these arrays, with the x axis being the frequency and the y axis the amplitude. I'm having difficulty figuring out how to input the arrays directly into the Google Charts code.
* google chartPHP

Avatar of undefined
Last Comment
Scott Fell

8/22/2022 - Mon
ASKER CERTIFIED SOLUTION
David Favor

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
msibley

ASKER
I cannot seem to find an example of coding with an array in php. I’ve found examples using hard-coded arrays for the data. I need it to work dynamically based on queries. For clarification, I’m not looking for examples of using a sql query to create the array. I want to pass arrays or a combined array.

Currently, as a workaround, I’m trying to use an example that imports a json data file, by outputting the arrays in a format similar to the example I have, and then using that file as the data source. Not very eloquent and it will require me to link to a new page to read the data in the <head> section, rather than handling it all in one fell swoop with one script.

Hopefully, thus makes sense. I’m just a self-taught junky code hack.
Norie

How are you creating/populating the arrays?

Are you manipulating/processing the data returned from your query in some way?
SOLUTION
Scott Fell

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
msibley

ASKER
Thanks to all who contributed. I experimented with writing a script to output data to a text file, then reading it in to the chart. This required me to link to another page, but it works. It isn't the solution I was looking for of doing it all in one fell swoop.
Your help has saved me hundreds of hours of internet surfing.
fblack61
David Favor

You're welcome!
Scott Fell

I think you can refine what you're doing into one Ajax request. that is what my example is trying to show.

you have an external page that accepts data input processes the data and outputs data for the chart.then your original page made the Ajax request is able to extract that and place it on the page where your chart is.

I think that maybe more confusing the right than it actually is. hopefully if you reread my example it'll make more sense.
Scott Fell

if you post what you're doing perhaps we can help refine here
⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.