3

I'm currently loading and rendering Highcharts by making a jquery getJSON call to a web service, like so:

$.getJSON('options.json')
    .done(function (chartOptions) {
            $('#chartholder').highcharts(chartOptions);
    });

This all works fine until I have to use an option that requires a javascript callback, such as axis label formatter. When I try it fails with an Uncaught TypeError exception and states the Object has no method 'call'.

I suspect this is as a result of the json, returned by the web service, wrapping the formatter property in quotes so it is valid json, but Highcharts expecting it to be a callback.

Is there a way to return a callback method in the json and for Highcharts to recognise it as such?

GrievousAngel
  • 261
  • 4
  • 10
  • In JSON you can't pass functions. You can pass string and then eval to function. See also [this topic](http://stackoverflow.com/questions/2001449/is-it-valid-to-define-functions-in-json-results). – Paweł Fus Oct 25 '13 at 09:39

1 Answers1

0

You can try to move you json options to script (come options.js). For example:

//options.js example
window.chartConfig = {
 charType: 'spline',
 tickPositioner: function() {console.log('bla-bla')}
}

// in some main script
$.getScript('options.js')
    .done(function () {
            window
            $('#chartholder').highcharts(window.chartConfig);
    });
Oleksandr Poshtaruk
  • 2,062
  • 15
  • 18