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

  • SEARCH
  • Home
  • 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 6903691
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T07:57:26+00:00 2026-05-27T07:57:26+00:00

I have a working flot graph, showing dynamically from sql using ajax. My problem

  • 0

I have a working flot graph, showing dynamically from sql using ajax. My problem is that, I can only plot one series. My other problem is the x-axis label. I wanted for the x-axis label to be pulled from sql date field dynamically.

this is my ajax:

function getPlot() {
        $.ajax({
            url: "ajax/ajax-totalplot.php",
            dataType: "json",
            async: false,
            success: function(result) {
                d = result;
                //console.log(d);
            }
        });
        var data = d; // HOW CAN I ADD THE DATE FOR X-AXIS LABEL?
        var datasets = [ {
            "data" : data, lines: { show: true }, points: {show: true}
        }];
        $.plot('#Plot', datasets); 
    }

this is the php

//run query    
    $sql = "SELECT date, bread, flower FROM `job` WHERE month(date) = 12 ORDER BY date";  

    $result = mysql_query($sql);

    while($row = mysql_fetch_array($result)) {
        $dd = date('d', strtotime($row['date'])); 
        $graphdata[] = array( (int)$dd, (int)$row['bread']);
    }


    print json_encode($graphdata); //HOW CAN I ADD THE FLOWER FIELD TO INCLUDE IN THE GRAPH AS WELL?
  • 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-27T07:57:26+00:00Added an answer on May 27, 2026 at 7:57 am

    To get a second data set, you need to produce another array of x,y values and then add it to datasets:

    In PHP:

       while($row = mysql_fetch_array($result)) {
            $dd = date('d', strtotime($row['date'])); 
            $graphdata[] = array( (int)$dd, (int)$row['bread']);
            $graphdata2[] = array( (int)$dd, (int)$row['flower']);
        }  
    
       print json_encode(array($graphdata,$graphdata2)); //maybe
    

    Then in JS:

    var datasets = [ 
    {
          "data" : data[0], lines: { show: true }, points: {show: true}
    },
    {
          "data" : data[1], lines: { show: true }, points: {show: true}
    } //second set of data is just another object in the datasets array
    ];
    $.plot('#Plot', datasets);
    

    To deal with dates, first check this example. The basic deal is to set the xaxis mode to “time” and then feed your dates from PHP into it as Javascript timestamps.

    So you need to change your creation of the $dd variable in PHP, and then when you call $.plot, add some options:

    //Change your SQL:
    $sql = "SELECT unix_timestamp(date)*1000, bread, flower FROM `job` WHERE month(date) = 12 ORDER BY date";  
    
    //change how you receive the date field:
    $dd = $row['date']
    
    //change how you call plot in JS:
    $.plot('#Plot',dataset,{
       xaxis: {
         mode: "datetime"
       }
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to simulate some code that I have working with SQL but using
I have been working with a string[] array in C# that gets returned from
Okay to get started I am using Jquery-Flot to plot a radial graph I
I have working with email option. i can send the Email using the intent
i have working codes from my server which is really working using Xampp server
I am working on a flot graph where i have a few data points
I have working code that opens up a word document programmatically using vbscript, makes
I have been working with Visual Studio (WinForm and ASP.NET applications using mostly C#)
I have been working on some legacy C++ code that uses variable length structures
I have a working copy of my project, checked out using Subversion 1.5.1. When

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.