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 8698521
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T01:44:55+00:00 2026-06-13T01:44:55+00:00

I have a multiple time series in a MySQL database that I am fetching

  • 0

I have a multiple time series in a MySQL database that I am fetching with PHP
(fetch_assoc) .

Each series has the same X axis but different Y axes.

X axis: datetime (POSIX values).

Y axes:

air_temperature
dew_point_temperature
sea_level_pressure
wind_direction
wind_speed_rate
sky_condition_total_coverage_code
liquid_precipitation_depth_dimension_one_hr
liquid_precipitation_depth_dimension_six_hr

I need to output this data in a specific JSON structure.
Here is an example of the proper end result:

{ "firstRow" : { "beginTime" : "2012-10-09 00:00:01",
      "endTime" : "2012-10-10 00:00:00",
      "tMax" : "56.0",
      "tMean" : "52.5",
      "tMin" : "49.0"
    },
  "interval" : "daily",
  "lastRow" : { "beginTime" : "2012-10-15 00:00:01",
      "endTime" : "2012-10-16 00:00:00",
      "tMax" : "72.0",
      "tMean" : "64.0",
      "tMin" : "56.0"
    },
  "series" : [ { "color" : "#FFAE28",
        "data" : [ [ 1349740801000,
              56
            ],
            [ 1349827201000,
              60
            ],
            [ 1349913601000,
              69
            ],
            [ 1350000001000,
              61
            ],
            [ 1350086401000,
              57
            ],
            [ 1350172801000,
              56
            ],
            [ 1350259201000,
              72
            ]
          ],
        "name" : "Maximum Temperature (ºF)",
        "type" : "spline",
        "yAxis" : 0,
        "zIndex" : 100
      },
      { "color" : "#4bf827",
        "data" : [ [ 1349740801000,
              52.5
            ],
            [ 1349827201000,
              56
            ],
            [ 1349913601000,
              59
            ],
            [ 1350000001000,
              55.5
            ],
            [ 1350086401000,
              49.5
            ],
            [ 1350172801000,
              49.5
            ],
            [ 1350259201000,
              64
            ]
          ],
        "name" : "Mean Temperature (ºF)",
        "type" : "spline",
        "yAxis" : 0,
        "zIndex" : 100
      },
      { "color" : "#2dc1f0",
        "data" : [ [ 1349740801000,
              49
            ],
            [ 1349827201000,
              52
            ],
            [ 1349913601000,
              49
            ],
            [ 1350000001000,
              50
            ],
            [ 1350086401000,
              42
            ],
            [ 1350172801000,
              43
            ],
            [ 1350259201000,
              56
            ]
          ],
        "name" : "Minimum Temperature (ºF)",
        "type" : "spline",
        "yAxis" : 0,
        "zIndex" : 100
      }
    ],
  "title" : "New York Laguardia Arpt: Daily Temperature",
  "xAxis" : { "max" : 1350259201000,
      "maxZoom" : 604800000,
      "min" : 1349740801000
    },
  "yAxis" : { "endOnTick" : false,
      "gridLineColor" : "#777",
      "gridLineWidth" : 1,
      "labels" : { "enabled" : true,
          "style" : { "color" : "#eee" }
        },
      "lineWidth" : 0,
      "max" : null,
      "maxPadding" : 0,
      "min" : null,
      "opposite" : false,
      "startOnTick" : true,
      "tickInterval" : null,
      "title" : { "style" : { "color" : "#eee" },
          "text" : "Degrees (Fahrenheit)"
        }
    }
}

Some help with this would be appreciated!

  • 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-06-13T01:44:56+00:00Added an answer on June 13, 2026 at 1:44 am

    You need to get the data from the database into a php array with the same structure as the javascript representation you want. Then you can use json_encode($arr_data) to create the javascript representation.

    In other words, your $arr_data must end up similar to this:

    $arr_data = array(
      "firstRow" => array(
                      "beginTime" => "2012-10-09 00:00:01",
                      "endTime" => "2012-10-10 00:00:00",
                      "tMax" => "56.0",
                      "tMean" => "52.5",
                      "tMin" => "49.0"
                     ),
      "interval" => "daily",
      "lastRow" => array(
                     "beginTime" => "2012-10-15 00:00:01",
                     "endTime" => "2012-10-16 00:00:00",
                     "tMax" => "72.0",
                     "tMean" => "64.0",
                     "tMin" => "56.0"
                   ),
       "series" => array(
          array(
            "color" => "#FFAE28",
            "data" => array(
                        array(1349740801000, 56),
                        array(1349827201000, 60),
                        etc...
                      ),
            "name" => "Maximum Temperature (ºF)",
            "type" => "spline",
            etc....
          )
        )
    );
    

    So, you must write a loop to create this php array, maybe something like this (depending on your db fields):

    if ($result = $mysqli->query($query)) {
      $arr_data = array();
      $i = 0;
      while ($row = $result->fetch_assoc()) {
        $arr_firstRow = array();
        $arr_firstRow["beginTime"] = $row["beginTime"];
        $arr_firstRow["endTime"] = $row["endTime"];
        etc...
        $arr_data[$i]["firstRow"] = $arr_firstRow;
        $arr_data[$i]["interval"] = $row["interval"];
        etc...
        $i++;
      }
    }
    

    And then, you can use json_encode($arr_data).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have table with date/time column and person column. Each person has multiple records
I have multiple textfields on my view, and each time a textfield is taped
I have this code to open multiple files one at a time that is
If I have mutliple, and at the same time, Ajax javascript queries on domain/somefile.php,
I have several time series plotted with jfreechart. The graph also contains multiple annotations.
I have a xts object (stock price time series) that is comprised of intraday
I have a (C#) genetic program that uses financial time-series data and it's currently
I want to place two Time Series Charts sharing the same time domain axis
I have a data frame containing multiple time series of returns, stored in columns.
I have a csv that I have imported that has multiple data fields for

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.