0

I'm using this PHP/CodeIgniter library for jQuery Highcharts: http://www.crustiz.com/php-jquery/highcharts-library-for-codeigniter/

The way that library does things is that it builds a PHP array of options, then converts it to json using json_encode (see line 273 of that library) which is then used by the jQuery Highcharts plugin. This is fine, except the option I'm trying to use is the tooltip formatter, which needs to be a javascript function, not a string (see http://www.highcharts.com/ref/#tooltip).

Since the library doesn't have a tooltip function, I created one as a test:

  function set_tooltip() {
    $this->a_options['tooltip']['formatter'] = 'function() { return this.series.name + "<br>" + this.x + ": " + this.y }';
    return $this;
  }

But this doesn't work as the JS function is output as a string, not a function. Anyone know if there is a way to have it be a function after passing through json_encode without rewriting that part of the library?

2
  • 1
    Whatever you're doing, sending the javascript over ajax probably isn't the most effective way to do it. Commented Oct 13, 2010 at 14:46
  • I'm not sending JS over ajax. Commented Oct 13, 2010 at 15:18

2 Answers 2

2

JSON isn't meant to convey functions. If you take a look at the documentation, there are only specifications for four types - object, array, string and number - plus the values true, false and null.

If you insist on doing this, perhaps an article like Sending Javascript Functions Over JSON will give you a hand.

Sign up to request clarification or add additional context in comments.

Comments

1

JSON doesn't have a "function callback" type so I think this is not possible. It knows only the basic types: string / number / object / array

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.