Note that there are some explanatory texts on larger screens.

plurals
  1. POConvert string representing object to javascript object
    text
    copied!<p>I'm currently using jqplot to display some charts and prepare javascript code with php.</p> <p>On one of my chart, I use Ajax to get a new chart. For this, I get a json array with the list of values and chart option as a string like this :</p> <p>This is the JSON I get : </p> <pre><code>{"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 }}}"} </code></pre> <p>And this is the part I have problem with : </p> <pre><code>"{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 }}}" </code></pre> <p>My problem is that in order to draw the chart with proper options, I need to pass this as a javascript object. And that what I can't figure how to do to convert my string to the corresponding javascript object.</p> <p>I tried to cast it as an object but without success, I've not so much ex^periences with javascript.</p> <p>Does anyone would have a solution or a tip ?</p> <p>Thanks</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload