Convert string representing object to javascript object -
i'm using jqplot display charts , prepare javascript code php.
on 1 of chart, utilize ajax new chart. this, json array list of values , chart alternative string :
this json :
{"idgraphe":"bar_chart_5","conditions":"[]","data":"[[[1,80423],[2,62634],[3,70625],[4,72187],[5,72739],[6,70078],[7,72751],[8,74300],[9,75550],[10,72482],[11,70971],[12,77579]],[[1,73386],[2,70068],[3,85018],[4,69761],[5,75317],[6,68240],[7,72487],[8,74716],[9,74340],[10,75012],[11,74800],[12,83105]]]","options":"{series : [{label : 'consommationtotale pilote1' , yaxis : 'yaxis' },{label : 'consommationtotale pilote2' , yaxis : 'yaxis' }] , seriesdefaults : {renderer : $.jqplot.barrenderer , rendereroptions : {barwidth : null} } , cursor : {show : true , zoom : true, showtooltip : false}, highlighter : {showtooltip : true , tooltipaxes : 'both' , tooltipcontenteditor : getpointinfo , show : true} , title : 'bar chart', legend : {show : true , renderer: $.jqplot.enhancedlegendrenderer}, axes : {xaxis:{ tickrenderer:$.jqplot.canvasaxistickrenderer , renderer: $.jqplot.categoryaxisrenderer,pad : 0 , label : 'mois' , labelrenderer: $.jqplot.canvasaxislabelrenderer}, yaxis:{ label : 'consommationtotale' , labelrenderer: $.jqplot.canvasaxislabelrenderer }}}"}
and part have problem :
"{series : [{label : 'consommationtotale pilote1' , yaxis : 'yaxis' },{label : 'consommationtotale pilote2' , yaxis : 'yaxis' }] , seriesdefaults : {renderer : $.jqplot.barrenderer , rendereroptions : {barwidth : null} } , cursor : {show : true , zoom : true, showtooltip : false}, highlighter : {showtooltip : true , tooltipaxes : 'both' , tooltipcontenteditor : getpointinfo , show : true} , title : 'bar chart', legend : {show : true , renderer: $.jqplot.enhancedlegendrenderer}, axes : {xaxis:{ tickrenderer:$.jqplot.canvasaxistickrenderer , renderer: $.jqplot.categoryaxisrenderer,pad : 0 , label : 'mois' , labelrenderer: $.jqplot.canvasaxislabelrenderer}, yaxis:{ label : 'consommationtotale' , labelrenderer: $.jqplot.canvasaxislabelrenderer }}}"
my problem in order draw chart proper options, need pass javascript object. , can't figure how convert string corresponding javascript object.
i tried cast object without success, i've not much ex^periences javascript.
does have solution or tip ?
thanks
some modern browsers have back upwards parsing json native object:
var x = "{series : [{label : 'consommationtotale pilote1' , yaxis : 'yaxis' },{label : 'consommationtotale pilote2' , yaxis : 'yaxis' }] , seriesdefaults : {renderer : $.jqplot.barrenderer , rendereroptions : {barwidth : null} } , cursor : {show : true , zoom : true, showtooltip : false}, highlighter : {showtooltip : true , tooltipaxes : 'both' , tooltipcontenteditor : getpointinfo , show : true} , title : 'bar chart', legend : {show : true , renderer: $.jqplot.enhancedlegendrenderer}, axes : {xaxis:{ tickrenderer:$.jqplot.canvasaxistickrenderer , renderer: $.jqplot.categoryaxisrenderer,pad : 0 , label : 'mois' , labelrenderer: $.jqplot.canvasaxislabelrenderer}, yaxis:{ label : 'consommationtotale' , labelrenderer: $.jqplot.canvasaxislabelrenderer }}}"; var result = json.parse(x);
for browsers don't back upwards it, can download json2.js json.org safe parsing of json object.
javascript string object
No comments:
Post a Comment