It is currently Sun Oct 26, 2014 5:35 am Advanced search

Access Series or Axis context in Axis and Tooltip formatters

Technical support, bug reports and more.

Access Series or Axis context in Axis and Tooltip formatters

Postby swilhelm » Mon Jan 09, 2012 9:11 pm

I am developing my own custom Axis and Tooltip Formatters. I would like the yAxis and Point labels to render values differently depending on the type of data being displayed (e.g. volume, percentage, US dollars, British Pound, etc.)

It is not possible to determine the type of data from just the single value or point. The context of the type of data is set on the series or chart. It is not set once statically. I retrieve different data sets dynamically using based on users inputs (e.g. financial instrument symbol .DJI, AAPL, BP.L, etc.).

I have not found a way to access the series or chart context from the Axis or Tooltip formatter. I have also not been able to find a way to reset the formatter in the Ajax "success" handler.

Any suggestions?
swilhelm
 
Posts: 2
Joined: Mon Jan 09, 2012 8:58 pm

Re: Access Series or Axis context in Axis and Tooltip format

Postby eolsson » Tue Jan 10, 2012 10:13 am

You have access to the series and chart instances via 'this' in the formatter, see http://www.highcharts.com/ref/#tooltip--formatter
http://jsfiddle.net/Er5dg/

Not sure I understand what reset of the formatter would do, but its not possible to first have a custom formatter and then later on remove that and use the default one.
Erik Olsson
Highsoft Solutions AS
eolsson
 
Posts: 396
Joined: Tue May 03, 2011 1:07 pm

Re: Access Series or Axis context in Axis and Tooltip format

Postby swilhelm » Tue Jan 10, 2012 5:14 pm

I see that that is true for tooltips, but not for the Axis formatter. Is there some other way to get access to the series or chart context from the Axis formatter.

Since I can't get access to the sensor or chart within the Axis formatter, I was attempting to set the Axis formatter to one of many different formatters in the ajax success based on the type of data that was being returned.

This also doesn't seem to work. Once Axis formatter is set, it can not be set to another function. Is this correct?
swilhelm
 
Posts: 2
Joined: Mon Jan 09, 2012 8:58 pm

Re: Access Series or Axis context in Axis and Tooltip format

Postby eolsson » Wed Jan 11, 2012 10:09 am

Yes you are right, once its set it cannot be changed. I'll add an issue about this, it really should be possible to access the chart from the axis formatter.

https://github.com/highslide-software/highcharts.com/issues/695
Erik Olsson
Highsoft Solutions AS
eolsson
 
Posts: 396
Joined: Tue May 03, 2011 1:07 pm

Re: Access Series or Axis context in Axis and Tooltip format

Postby eolsson » Wed Jan 11, 2012 11:07 am

It's not part of an official release yet, but I just added `axis` and `chart` to this-context in the axis formatters, so the following is now possible:

Code: Select all
    yAxis: {       
        labels: {
            formatter: function() {
                console.log(this.axis); // Current Axis instance
                console.log(this.chart); // The Chart instance
                return this.value +' - ' + this.chart.options.chart.renderTo;
            }
        }
    }


Example: http://jsfiddle.net/MQVyk/

Link to the latest development version: https://raw.github.com/highslide-software/highcharts.com/master/js/highcharts.src.js
Erik Olsson
Highsoft Solutions AS
eolsson
 
Posts: 396
Joined: Tue May 03, 2011 1:07 pm


Return to Highcharts Usage

Who is online

Users browsing this forum: Bing [Bot] and 6 guests

cron