Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6357127
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T23:06:21+00:00 2026-05-24T23:06:21+00:00

I’m trying to populate a Flot chart with data from a MySQL query in

  • 0

I’m trying to populate a Flot chart with data from a MySQL query in PHP. I’m sure this is a crappy way to go about things (without Ajax or JSON, neither of which I’m comfortable with yet), but I output the query results in the format Flot needs for its data points into a hidden div on my PHP page, like so:

function get_team_chart($arr) {
    $data1 = array();
    $data2 = array();
    foreach ($arr as $a) {
        $data1[] = '[' . $a['week'] . ',' . $a['pts'] . ']';
        $data2[] = '[' . $a['week'] . ',' . $a['league_avg'] . ']';
    }
    $str1 = implode(', ', $data1);
    $str2 = implode(', ', $data2);
    echo "  <div id='series1' style='display:none;'>" . $str1 . "</div>
            <div id='series2' style='display:none;'>" . $str2 . "</div>";           
}

Then I try to pull that data into my chart in JavaScript like so:

function plot_team_chart() {
    var series1 = $('#series1').html();
    var series2 = $('#series2').html();
    $.plot( $("#team-chart"),
            [   series1,
                series2],
            {   xaxis: {min:0,
                        max:13},
                yaxis: {max:150,
                        min:0}}
    );

}

This doesn’t throw any JS errors at runtime, and the chart shows up with the specified mins and maxes, but no data is plotted. I checked the values of series1 and series2 and they are both without quotes around the numerical values (i.e. they are like [1,120.3], [2,89.0], not like ["1","120.3"], ["2","89.0"]).

This is my first foray into the world of Flot, so please be gentle. Also, I verified that the chart plots fine with hardcoded values.

Thank you.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T23:06:23+00:00Added an answer on May 24, 2026 at 11:06 pm

    Got it working. Feel free to respond with how this functionality would be accomplished with Ajax and/or JSON, but here is how I accomplished pulling in data within a hidden div to plot on Flot:

    function plot_team_chart() {
        var tmp1 = new Array();
        var tmp2 = new Array();
        var tmp3 = new Array();
        var data = new Array();
        $('.to-plot').each(function() {
            tmp1 = $(this).html().split('|');
            for (var i=0; i<tmp1.length; i++) {
                tmp2 = tmp1[i].split(',');
                tmp3.push(tmp2);
            }
            data.push({ label: $(this).attr('data_label'),
                        data: tmp3});
            tmp3 = [];
        });
    
        var options = { xaxis: {    min:1,
                                    max:13},
                        yaxis: {    max:120,
                                    min:30},
                        grid: {     borderColor:'#ccc'},
                        legend: {   show:true,
                                    position:'se'}};
    
        if (data.length > 0) {
            $.plot( $("#team-chart"),
                    data,
                    options
            );
        }
    }
    

    And the modified PHP to accommodate the changes:

    function get_team_chart($arr) {
        $data1 = array();
        $data2 = array();
        foreach ($arr as $a) {
            $data1[] = $a["week"] . "," . $a["pts"];
            $data2[] = $a["week"] . "," . $a["league_avg"];
        }
        $str1 = implode('|', $data1);
        $str2 = implode('|', $data2);
        echo "  <div id='series1' data_label='avg score' style='display:none;'>" . $str1 . "</div>
                <div id='series2' data_label='league avg' style='display:none;'>" . $str2 . "</div>";           
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to use string.replace('’','') to replace the dreaded weird single-quote character: ’ (aka
I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and
I have a text area in my form which accepts all possible characters from
I am writing an app with both english and french support. The app requests
I'm parsing an XML file, the creators of it stuck in a bunch social
I am using Paperclip to handle profile photo uploads in my app. They upload

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.