Veera S
Veera S

Reputation: 5

Customize Highchart tooltip

I want to customize my tooltip. I want position certain series at a certain places. Like 2 series on top and 2 series on bottom. I want this to look like this

Original

Modified

https://jsfiddle.net/gh/get/library/pure/highcharts/highcharts/tree/master/samples/highcharts/demo/column-placement/

Also, how do I add arrow in the tooltip as well? Right now it comes only as a box.

Highcharts.chart('container', {
    chart: {
        type: 'column'
    },
    title: {
        text: 'Efficiency Optimization by Branch'
    },
    xAxis: {
        categories: [
            'Seattle HQ',
            'San Francisco',
            'Tokyo'
        ]
    },
    yAxis: [{
        min: 0,
        title: {
            text: 'Employees'
        }
    }, {
        title: {
            text: 'Profit (millions)'
        },
        opposite: true
    }],
    legend: {
        shadow: false
    },
    tooltip: {
        shared: true
    },
    plotOptions: {
        column: {
            grouping: false,
            shadow: false,
            borderWidth: 0
        }
    },
    series: [{
        name: 'Employees',
        color: 'rgba(165,170,217,1)',
        data: [150, 73, 20],
        pointPadding: 0.3,
        pointPlacement: -0.2
    }, {
        name: 'Employees Optimized',
        color: 'rgba(126,86,134,.9)',
        data: [140, 90, 40],
        pointPadding: 0.4,
        pointPlacement: -0.2
    }, {
        name: 'Profit',
        color: 'rgba(248,161,63,1)',
        data: [183.6, 178.8, 198.5],
        tooltip: {
            valuePrefix: '$',
            valueSuffix: ' M'
        },
        pointPadding: 0.3,
        pointPlacement: 0.2,
        yAxis: 1
    }, {
        name: 'Profit Optimized',
        color: 'rgba(186,60,61,.9)',
        data: [203.6, 198.8, 208.5],
        tooltip: {
            valuePrefix: '$',
            valueSuffix: ' M'
        },
        pointPadding: 0.4,
        pointPlacement: 0.2,
        yAxis: 1
    }]
});

Upvotes: 0

Views: 2677

Answers (1)

Core972
Core972

Reputation: 4114

To do something like that you will need to use the tooltip.formatter Api doc and some CSS.

JS

tooltip: {      
    shared: true,
    useHTML:true,
    formatter: function(){
            var text = this.x + '<br>';
        text+= '<span class="number"><span style="color:' + this.points[0].color + '">\u25CF</span>' + this.points[0].series.name + '</span><span class="number">' + '<span style="color:' + this.points[1].color + '">\u25CF</span>' + this.points[1].series.name + '</span><br>';

        text+= '<span class="number">' + this.points[0].y+ '</span><span class="number">' +this.points[1].y+ '</span></br>'

        text+= '<span class="number"><span style="color:' + this.points[2].color + '">\u25CF</span>' + this.points[2].series.name + '</span><span class="number">' + '<span style="color:' + this.points[3].color + '">\u25CF</span>' + this.points[3].series.name + '</span><br>';

        text+= '<span class="number">' + this.points[2].y+ '</span><span class="number">' +this.points[3].y+ '</span></br>'
        return text;
    }
},

CSS

.number{
  width:34%;
  padding:1%;
  display:inline-block;
  text-align:center;
}

Fiddle

Upvotes: 1

Related Questions