Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>From amCharts: "amCharts does not directly support JSON. It's not loading external data files or anything. It just uses native JavaScript data objects. So it's really up to browser's JS parser what format of data it can or can't read."</p> <p><a href="http://www.amcharts.com/forum/viewtopic.php?id=7049" rel="nofollow">http://www.amcharts.com/forum/viewtopic.php?id=7049</a></p> <p>I'm assuming you have more than one chart and building out custom string formatters for each may be a bit cumbersome compared to the easy of use of the default json or RABL formats.</p> <p>What you can also do is create a common javascript function and use a little RegEx to filter the JSON to a amCharts friendly format.and</p> <pre><code>function CleanJSONForAMCharts(json) { return json.replace(/"(\w+)"\s*:/g, '$1:'); } </code></pre> <p>Now this is still of course a string now and not the array of object amCharts is expecting. Eval() must be called on the returned string before it can be passed to dataProvider.</p> <pre><code>//sample data that would have been returned from a RESTful service or another JSON returning method var chartData = CleanJSONForAMCharts("[{\"title\":\"sample 1\",\"value\":130},{\"title\":\"sample 2\",\"value\":26}]"); var chart = new AmCharts.AmSerialChart(); chart.categoryField = "title"; chart.dataProvider = eval(chartData); var graph = new AmCharts.AmGraph(); graph.valueField = "value"; graph.type = "column"; graph.fillAlphas = 1; chart.addGraph(graph); chart.write("chartdiv"); </code></pre>
 

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