Accepted answer

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


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


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.


I had the same problem with a c# array, I solve in this way with razor :

    string[] myIntArray = new string[5] {"Apples", "Oranges", "Pears", "Grapes", "Bananas" };
    var serializer = new System.Web.Script.Serialization.JavaScriptSerializer();
    var jsVariable = serializer.Serialize(myIntArray);  

xAxis: {
    categories: @Html.Raw(jsVariable)

Related Query

More Query from same tag