Solved

Flot chart powered by mysql database

Posted on 2012-12-24
1
3,420 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

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

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

Suggested Solutions

In this article you'll learn how to use Ajax calls within your CodeIgniter application. To explain this, I'll illustrate how to implement a simple contact form to allow visitors to send you an email through your web site.
Since pre-biblical times, humans have sought ways to keep secrets, and share the secrets selectively.  This article explores the ways PHP can be used to hide and encrypt information.
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

832 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