Such a problem arose:
From the server via ajax I get data, in the js cycle I form json in order to substitute the function that builds the graphics. Faced a striking thing: if you display the contents of a variable, for example through document.write on the screen, copy and substitute, everything works, and if you directly substitute, then it writes
Uncaught TypeError: Cannot call method 'match' of undefined
alert produces quite a valid code ...
JSON of this type:
[{"period":"2014-5-5","ΠΠ»ΠΈΠ΅Π½ΡΡ":"1000","ΠΡΠΎΠ΄Π°ΠΆΠΈ":"500"},{"period":"2014-5-5","ΠΠ»ΠΈΠ΅Π½ΡΡ":"1000","ΠΡΠΎΠ΄Π°ΠΆΠΈ":"500"}..... ΠΈ Ρ.Π΄. ]
Formation in a cycle:
to_chart += "{"+"\"period\":"+"\""+chart_sub[0]+"-"+chart_sub[1]+"-"+chart_sub[2]+"\""+","+"\"ΠΠ»ΠΈΠ΅Π½ΡΡ\":"+"\""+chart_sub[3]+"\""+","+"\"ΠΡΠΎΠ΄Π°ΠΆΠΈ\":"+"\""+chart_sub[4]+"\""+"}"+",";
Substitute the function:
var tc = "["+to_chart+"]"; Morris.Line({ element: 'staff_chart_container', **data: tc,** xkey: 'period', ykeys: ['ΠΠ»ΠΈΠ΅Π½ΡΡ', 'ΠΡΠΎΠ΄Π°ΠΆΠΈ'], labels: ['ΠΠ»ΠΈΠ΅Π½ΡΡ', 'ΠΡΠΎΠ΄Π°ΠΆΠΈ'], smooth: true, lineColors: ["#336699","#009245"], hideHover:true });
Tell me the decision, friends)