score:5

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
},

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.

score:1

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