6elephants
6elephants

Reputation: 323

Highcharts Series name on X-Axis

I have this column chart http://jsfiddle.net/TU7TL/ I am wondering if there is a way to get the series name to appear under its respective column, for example "Tokyo" would be directly under the blue bar rather than just in the legend. Code below

$(function () {
    $('#container').highcharts({
        chart: {
            type: 'column'
        },
        title: {
            text: 'Monthly Average Rainfall'
        },
        subtitle: {
            text: 'Source: WorldClimate.com'
        },
        xAxis: {
            categories: [
                'Tokyo',
                'New York',
                'London'
            ]
        },
        yAxis: {
            min: 0,
            title: {
                text: 'Rainfall (mm)'
            }
        },
        tooltip: {
            headerFormat: '<span style="font-size:10px">{point.key}</span><table>',
            pointFormat: '<tr><td style="color:{series.color};padding:0">{series.name}: </td>' +
                '<td style="padding:0"><b>{point.y:.1f} mm</b></td></tr>',
            footerFormat: '</table>',
            shared: true,
            useHTML: true
        },
        plotOptions: {
            column: {
                pointPadding: 0.2,
                borderWidth: 0
            }
        },
        series: [{
            name: 'Tokyo',
            data: [49.9]

        }, {
            name: 'New York',
            data: [83.6],


        }, {
            name: 'London',
            data: [48.9]

        }, {
            name: 'Berlin',
            data: [42.4]

        }]
    });
});

Upvotes: 0

Views: 9143

Answers (1)

ElLocoCocoLoco
ElLocoCocoLoco

Reputation: 385

Complete the categories as:

categories: [
                    'Tokyo',
                    'New York',
                    'London',
                    'Berlin'
                ]

then the stacking option as:

plotOptions: {
                column: {
                    pointPadding: 0.2,
                    borderWidth: 0,
                    stacking: 'normal'
                }
            }

Then your data in series as:

series: [{
                name: 'Tokyo',
                data: [49.9,null,null,null]

            }, {
                name: 'New York',
                data: [null,83.6,null,null],


            }, {
                name: 'London',
                data: [null,null,48.9,null]

            }, {
                name: 'Berlin',
                data: [null,null,null,42.4]

            }]

Here you have the Fiddle:

http://jsfiddle.net/TU7TL/1/

Alternatively you can do it using only one serie, and putting all your data in the serie array like that:

series: [{
            name: 'Measure',
            data: [{y:49.9, color: colors[0]},{y:83.6, color: colors[1]},{y:48.9, color: colors[2]},{y:42.4,color: colors[3]}]

        }]
    });

With this last method you have to specify the different colors in the same serie. previously I declare and use a variable "colors", to get the colors from Highchart:

var colors = Highcharts.getOptions().colors;

The fiddle Example is here: http://jsfiddle.net/TU7TL/4/

Upvotes: 2

Related Questions