ajax - passing formatting JavaScript code to HighCharts with JSON -
i have website uses ajax deliver json formatted string highcharts chart.
you can see middle json code part at:
http://jsfiddle.net/1loag7pv/
$('#container').highcharts( //json start { "plotoptions": { "series": {"animation": {"duration": 500}} ,"pie": { "allowpointselect": true, "cursor": "pointer", "datalabels": {"formatter":function(){return this.point.name+': '+this.percentage.tofixed(1) + '%';}} } }, "chart":{"renderto":"divreportchart"} ,"title":{"text":"sales totals"} ,"xaxis":{"title":{"text":"item"}, "categories":["taxes","discounts","netsalestotal"], "gridlinewidth":1} ,"yaxis":[{"title":{"text":"amount"}, "gridlinewidth":1}] ,"series":[{"name":"amount","type":"pie", "startangle": -60,"yaxis": 0,"data":[["taxes",17.8700],["discounts",36.0000],["netsalestotal",377.9500]]}] } //json end );
the problem function part...
"datalabels": {"formatter":function(){return this.point.name+': '+this.percentage.tofixed(1) + '%';}}
is not beingness transferred via json
all research tells me there no way this.
ie... is valid define functions in json results?
anybody got thought on how around limitation?
it true cannot pass functions in json. javascript superset of json.
a mutual approach chart defined in javascript (e.g. during page load), , page requests info via ajax. when info returned can added chart object, either before rendered or afterwards using highcharts api.
if want pass formatter function server chart, send string, , turn function this:
var fn = function(mystring);
and utilize in highcharts like:
chart.plotoptions.pie.datalabels = {"formatter":fn};
i've re-factored illustration show approach: http://jsfiddle.net/wo7zn0bw/
javascript ajax json highcharts
No comments:
Post a Comment