score:1

Accepted answer

The issue is the use of this.x here:

for (i = 0; i < 4; i++) {
    sum += series[i].yData[this.x];
}

For "normal" x-axis types this works well since you can open the yData by index. In your case it will end up trying to find something like series[0].yData[1262304000000], which won't work.

I'm not aware of any easy way to find the relationship between the timestamp this.x and which index that has on the x-axis. My solution uses another for loop to compare the timestamp from this.x with the xData array, and if it matches we use the data in the sum, as shown in this updated formatter:

formatter: function () {
    // If doing negative, ignore
    if(this.total <= 0)
        return;

    var sum = 0;
    var series = this.axis.series;

    for (var i = 0; i < series.length; i++){
        for(var j = 0; j < series[i].xData.length; j++) {
            if(series[i].options.type == 'column' && series[i].xData[j] == this.x) {
                sum += series[i].yData[j];
                break;
            }
        }
    }

    return sum;
}

This updated JSFiddle shows it in action.

score:1

If I understand what you're asking for correctly, the following formatter function should work:

        formatter: function () {
            return this.total >= 0 ?this.total : null ;
        },

http://jsfiddle.net/aTh7F/1/

As to the available options in the formatter function, http://api.highcharts.com/highcharts#plotOptions.column.dataLabels.formatter should help. But, I tend to just put a breakpoint in the function and inspect what this is. :)


Related Articles