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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T11:26:33+00:00 2026-05-26T11:26:33+00:00

I’m trying to convert a php array of items to labels for a Highcharts

  • 0

I’m trying to convert a php array of items to labels for a Highcharts X-axis. The default example is:

categories: ['Jan','Feb','Mar','Apr', 'May', 'Jun', 
                    'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec']

So I have a PHP array ($items) and end up with a Javascript array (var items). Firebug outputs the following:

console.log(items);
["item1_10_20", "item2_2011_10_14", "item3_2011_10_07", "item3_2011_09_12"]

I can see that I should have single quotes, instead. How can I do that? Or maybe I should feed Highcharts with a comma and single-quoted separated string instead? How do I do either?


EDIT

I’ve tried this, but no luck at all!

in my view file I have a javascript script:

var items = "'<? echo join("','", $items) ?>'"; // Note the enclosing single quotes

And in the Highcharts JS file:

xAxis: {
 categories: [items]
},

The whole array is placed in the first value of the x-axis and the rest of the values are blank. The item variable is shown in firebug:

'item1_2011_10_20','item2_2011_10_14','item3_2011_10_07','item4_2x1_2011_09_12'

How weird is this not working?


EDIT

When using json_encode to format the php array, I still can’t get highcharts to recognize the array. If I manually copy and hardcode the array with single quotes, it works. But I really need to pass the array from php to highcharts’ js via variables.

Here’s the resulting x-axis with an array via json_encode:
Chart with bad x-axis

  • 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-26T11:26:34+00:00Added an answer on May 26, 2026 at 11:26 am

    The following is already an array –

    ["item1_10_20", "item2_2011_10_14", "item3_2011_10_07", "item3_2011_09_12"]
    

    so, change the following

    xAxis: {
        categories: [items]
    },
    

    as follows –

    xAxis: {
        categories: items
    },
    

    Update:

    xAxis: {
        categories: eval('(' + items + ')')
    },
    

    Update2:

    One thing you need to know here is that JSON is not Javascript. You get get JSON reponse from server which is nothing more than a string in Javascript. So, to use that JSON response in Javascript you have to parse the JSON to form a Javascript data structure like object, array, etc (Just like we do with XMl), which is called parsing.

    There are a lot of JSON parsing libraries, but we can also use eval JS function to do the job, as long as security is not a concern.

    And in your case, the JSON response represents an array so you use eval to turn that into a real Javascript array.

    So, items is JSON and you use eval (eval('(' + items + ')')) to parse which returns a Javascript array and then you assign the result to categories.

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

Sidebar

Related Questions

I'm trying to create an if statement in PHP that prevents a single post
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I want to count how many characters a certain string has in PHP, but
I would like to count the length of a string with PHP. The string
this is what i have right now Drawing an RSS feed into the php,
I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this

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.