1
votes

I have my export server up and running an am using to generate all charts on the server. One issue I am having is with datalabels. If I use format it works ok but I need formatter and it does not appear to be called. This is the relevant portion of my options:

 dataLabels: {
            enabled: true,
            color: '#606060',
            align: 'right',
            //format:'{point.y:.0f}',
            formatter:function(){

                var val = this.y;

                return val / 1000000 + 'M';

            },

Since the value just gets displayed normally it appears that this function just does not get called. When I use these exact options on client it works fine. Is this not possible?

UPDATE: I have my own export server (highcharts-converter.js) as I am doing this all on the server with phantomjs. What I do is fetch data from another service and then build the infile like I would on the client. Problems I have run into are 1. doing JSON.stringify on infile gets rid of formatter functions. 2. If I make the function strings that does not work either because I have to call a webservice for the highcharts phantomjs. This means that the config automatically gets converted to JSON and when converter does a JSON.parse the functions remain strings. Not sure if I need to change highcharts-convert.js to somehow turn them back into functions but can't figure out how and am not sure how to debug that file since it is on a separate process (phantomjs child process). Have tried just about everything I can think of to fix this but no luck so far.

ALSO: Because the function is a string highcharts throws this error: TypeError: 'undefined' is not a function (evaluating 'axis.labelFormatter.call')

1
Using the Highcharts export server, it works: jsfiddle.net/0gt60Lrx/1, can you create a reproducible example? - Mark

1 Answers

0
votes

I found a solution though not sure if it's the best one. I call json.stringify and then override it. I then turn the function into a string so that when it gets sent in the post call it does not get removed. Then in highcharts-convert.js I turn it back into a function.

sorry took so long to get back. Been a while but I believe this is it. To stringify I did this:

function toJSONWithFuncs(obj) {
Object.prototype.toJSON = function() {
    var sobj = {}, i;
    for (i in this)
        if (this.hasOwnProperty(i))
            sobj[i] = typeof this[i] == 'function' ?
                this[i].toString() : this[i];

    return sobj;
};

var str = JSON.stringify(obj);

delete Object.prototype.toJSON;

return str;

}

then in highcharts-convert.createChart I do this right before page.open

input = params.infile;
input = input.replace(/:"function/g,':function');
input = input.replace(/(}\|")/g,'}');