Solved

Flot chart powered by mysql database

Posted on 2012-12-24
1
3,353 Views
Last Modified: 2013-02-08
Hi,

I have a flot chart page that is working fine with static values. But I want this to be driven from mysql, so its up to date. This is where I'm stuck on how to get the data to link to the charts.

I'm using framework fuel php, php 5.3, mysql 5.5. I will be having multiple graphs on the page and at present I have a $data array that currently brings back 2 different query results. So I have $results and $results2.

My first graph needs to take values from $results. I've looked for example online but don't seem to be getting anywhere.

Does anyone have a guide for this I could follow? Currently PHP file with the flot is below, I would also want my xaxis to be driven from the database as well.

Thanks
<script>

$(function () {
    var css_id = "#placeholder";
    var data = [
        {label: 'Calls', data: [[1,300], [2,300], [3,300], [4,300], [5,300]]},
        {label: 'Minutes', data: [[1,800], [2,600], [3,400], [4,200], [5,0]]},
    ];
    var options = {
        series: {
                 lines: {show: true, steps: false },},
                // bars: {show: true, barWidth: 0.9, align: 'center',},},
        xaxis: {ticks: [[1,'Monday'], [2,'Tuesday'], [3,'Wednesday'], [4,'Thursday'], [5,'Friday']]},
        points: {  
        show: true,  
        radius: 4  
    }  
    };

    $.plot($(css_id), data, options);
});
</script>

Open in new window

0
Comment
Question by:andybrooke
1 Comment
 
LVL 15

Accepted Solution

by:
StealthyDev earned 500 total points
ID: 38719708
Hi,

You can create a JSON, array for xaxis and dynamically populate it in PHP and assign to the attribute.

Have a look at the below thread.

http://stackoverflow.com/questions/1312302/retrieve-data-from-mysql-by-php-to-create-flot-graph#1312446

Thanks,
Senthur
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

This article discusses four methods for overlaying images in a container on a web page
This article discusses how to create an extensible mechanism for linked drop downs.
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

911 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now