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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T16:37:43+00:00 2026-06-11T16:37:43+00:00

I am using HighCharts Bar graph to plot data from mysql resultset into a

  • 0

I am using HighCharts Bar graph to plot data from mysql resultset into a bar graph.

Now the resultset of my query is as below:

Name       Expense
-----------------
July       700.0000
August     450.0000  
September  1700.0000

The series property of HighCharts require data in below format to plot the graph

[
 {name:"July",data:[700.0000]},
 {name:"August",data:[450.0000]},
 {name:"September",data:[1700.0000]}
] 

So I thought of coverting my resultset into a JSON object using json_encode($row).
But I got the following output:

[{"name":"July","data":"700.0000"},
 {"name":"August","data":"450.0000"},
 {"name":"September","data":"1700.0000"}] 

Doubts:

  1. Is there a way to get/convert the resultset in exactly the same format as is required by the series property of HighCharts?
  2. Also can I use an object of created in the php block, directly into the javascript? Say I create an object $jsonNameData out of my resultset. Then can I use it in the javascript as

    series: <? echo $jsonNameData ?>

EDIT:

I was able to solve Q1 by doing the following:

$count = 0;
$strSeries = "[";
while($r = mysql_fetch_assoc($result)) {

   if($count == 0){
       $strSeries .= "{name:'" . $r['name'] . "',";
       $strSeries .= "data:[" . $r['data'] . ']}';
       $count = 1;
   }
   else {
       $strSeries .= ",{name:'" . $r['name'] . "',";
       $strSeries .= "data:[" . $r['data'] . ']}';
   }
 $rows[] = $r;
}
$strSeries .= "]";

Got the required string into $strSeries.

Now the problem is the second question. I assigned the value of $strSeries to a variable in javascript but when I use that variable as

series: variableName

It is not plotting the graph properly even though the variable has proper value (checked through alert).

  • 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-11T16:37:44+00:00Added an answer on June 11, 2026 at 4:37 pm

    Not got a chance to run the code below, but this should work or something very similar to this

    $series=array();
    while($item = mysql_fetch_assoc($result)) {
      $serie=array(
         "name" => $item['name'],
         "data" => array(floatval($item['data']))
      );
      array_push($series,$serie);
    }
    echo json_encode($series);
    

    An advice is to always stick to json_encode() for doing the jsonification. You may want to go through this example on the reference page to learn about how json_encode works with arrays in particular

    EDIT: To answer your 2nd question. You may be getting a highchart error #14 in the javascript console? Have a look at this question Highcharts returning error 14

    P.S. Please don’t mix multiple questions in one, post them separately, also use tools like javascript console and SO search more effectively

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

Sidebar

Related Questions

I'm trying to plot a bar graph using HighCharts. So far so good, but
I'm using Highcharts to represent groups of time series. So, data points collected from
I've got this code I'm using to insert data into Highcharts def self.amount_on(date) where(date(created_at)
I am using a bar chart below. chart = new Highcharts.Chart({ chart: { renderTo:
I am using highcharts to generate graphical data pulled from a database. I am
Using highcharts, how would I put a default grey bar under my column charts,
I want to add a background image to a bar chart using Highcharts and
I am using HighCharts for a line graph and i am attemping to change
I am using Highcharts to draw a line graph. When the page loads, the
I am learning JS from scratch and implementing HighCharts code using JS. Seeing one

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.