javascriptjqueryjsonhighchartsphantomjs

Highcharts server side image generation, how to set up legend labelFormatter in callback argument


I'am working on a PDF file generator that user Highcharts server side image generation to populate graph information in the document.

http://www.highcharts.com/docs/export-module/render-charts-serverside

Everything work great and i would customize my highchart legend to get one legend per line at the bottom of the graph. Because the server side generation use JSON format, i could not set the "legend.labelFormatter" callback to force break line after each legend.

There is a simple exemple in the readme of source code, but I can not fit my needs. (https://github.com/highcharts/highcharts/tree/v3.0.0/exporting-server/phantomjs)

The readme exemple :

function(chart) {
    chart.renderer.arc(200, 150, 100, 50, -Math.PI, 0).attr({
        fill : '#FCFFC5',
        stroke : 'black',
        'stroke-width' : 1
     }).add();
}

My own callback

function(chart){

    console.log('COOL!');

    chart.legend.labelFormatter = function () {


        console.log('COOL 2!');


        return this.name + "\n";
    };

    chart.redraw();

}

Solution

  • I think there are two solutions (at least) to get what you need:

    Anyway, have you tried to use labelFormatter? I know it's JSON, but I think it works.