Solved

Flot chart powered by mysql database

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

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

Suggested Solutions

I found this questions asking how to do this in many different forums, so I will describe here how to implement a solution using PHP and AJAX. The logical flow for the problem should be: Write an event handler for the first drop down box to get …
This article demonstrates how to create a simple responsive confirmation dialog with Ok and Cancel buttons using HTML, CSS, jQuery and Promises
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

763 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

7 Experts available now in Live!

Get 1:1 Help Now