Note that there are some explanatory texts on larger screens.

plurals
  1. POHowto correctly format json_encode from class?
    primarykey
    data
    text
    <p>I can't get my json correctly formatted the way i want/need. I'm using open-flash-charts for this and my graph doesn't accept the json i give it... Everything is done inside the php that open-flash-chart uses as data file. I'm just echoing my json, could this be the problem or json-format style??</p> <pre><code>class Charts { public $title = ["title"=&gt;['text' =&gt; "ae", 'style' =&gt; "za"]]; public $y_legend = ["y_legend"=&gt;['text' =&gt; "", 'style' =&gt; ""]]; public $x_axis = ["x_axis"=&gt;['stroke' =&gt; '1', 'tick_height' =&gt; '10', 'colour' =&gt; "#d000d0", 'grid_colour' =&gt; "#00ff00", 'labels' =&gt; [] ]]; public $y_axis = ["y_axis"=&gt;['stroke' =&gt; '1', 'tick_length' =&gt; '10', 'colour' =&gt; "#d000d0", 'grid_colour' =&gt; "#00ff00", 'offset' =&gt; '0', 'max' =&gt; '20']]; public $bar = ["elements"=&gt;['type' =&gt; "bar", 'alpha' =&gt; '0.5', 'colour' =&gt; '#9933CC', 'text' =&gt; "", 'font-size' =&gt; '10', 'values' =&gt; [] ]]; public $pie = ["elements" =&gt; ['type' =&gt; "pie", 'start_angle' =&gt; '180', 'colours' =&gt; ["#d01f3c","#356aa0","#C79810","#73880A","#D15600","#6BBA70"], 'alpha' =&gt; '0.6', 'stroke' =&gt; '2', 'animate' =&gt; '0', 'values' =&gt; [] ]]; } $a = new Charts(); $a-&gt;title['title']['text'] = "Dates"; $a-&gt;title['title']['style'] = "{font-size: 20px; color:#0000ff; font-family: Verdana; text-align: center;}"; $a-&gt;y_legend['y_legend']['text'] = "Khash/s"; $a-&gt;y_legend['y_legend']['style'] = "{font-size: 10px; color:#0000ff; font-family: Verdana; text-align: center;}"; $a-&gt;x_axis['x_axis']['labels'] = get_val_date($poolstale_enc_json); // Function returns an array of values $a-&gt;bar['elements']['text'] = "barText"; $a-&gt;bar['elements']['values'] = get_val_value($poolstale_enc_json);// Function returns an array of values $all_data = $a-&gt;title; $all_data += $a-&gt;y_legend; $all_data += $a-&gt;x_axis; $all_data += $a-&gt;bar; echo json_encode($all_data); </code></pre> <p>This gives as output:</p> <pre><code>{ "title":{ "text":"Dates", "style":"{font-size: 20px; color:#0000ff; font-family: Verdana; text-align: center;}" }, "y_legend":{ "text":"Khash\/s", "style":"{font-size: 10px; color:#0000ff; font-family: Verdana; text-align: center;}" }, "x_axis":{ "stroke":"1", "tick_height":"10", "colour":"#d000d0", "grid_colour":"#00ff00", "labels":[ "2013-08-25" ] }, "elements":{ "type":"bar", "alpha":"0.5", "colour":"#9933CC", "text":"barText", "font-size":"10", "values":[ "2.96" ] } } </code></pre> <p>but i need to have correct format because my charts won't accept this json. Example correct by their site:</p> <pre><code>{ "title":{ "text":"Many data lines", "style":"{font-size: 30px;}" }, "y_legend":{ "text":"Open Flash Chart", "style":"{font-size: 12px; color:#736AFF;}" }, "elements":[ { "type": "line", "colour": "#9933CC", "text": "Page views", "width": 2, "font-size": 10, "dot-size": 6, "values" : [15,18,19,14,17,18,15,18,17] }, { "type": "line_dot", "colour": "#CC3399", "width": 2, "text": "Downloads", "font-size": 10, "dot-size": 5, "values" : [10,12,14,9,12,13,10,13,12] }, { "type": "line_hollow", "colour": "#80a033", "width": 2, "text": "Bounces", "font-size": 10, "dot-size": 6, "values" : [5,7,9,7,4,6,1,2,5] } ], "y_axis":{ "max": 20 }, "x_axis":{ "steps": 2, "labels": ["January","February","March","April","May","June","July","August","September"] } } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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