Wjdavis5
Wjdavis5

Reputation: 4151

HighCharts Place Label on Bar

Given the below image - I would like to take the label from the legend for each column and print it on the column itself. I have not been able to find anything in the HighCharts API that will allow me to do this. Does anyone have any ideas or examples of something like this I could look at?

Thank you!

HighChart Exampl

EDIT

There is a better example of what I want to accomplish

I think that is easily discernible. The use case is these stats are displayed on large monitors around a call center. The legend is typically too small to read from any given distance.

Upvotes: 6

Views: 19425

Answers (2)

GGG
GGG

Reputation: 817

Just try formatting the data label on a column chart, here is an example to get you started.

 $(function () {
        $('#container').highcharts({
            chart: {
                type: 'column'
            },
            xAxis: {
                categories: ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec']
            },

            plotOptions: {
                series: {
                    dataLabels: {
                        enabled: true,
                        color: '#000',
                        style: {fontWeight: 'bolder'},
                        formatter: function() {return this.x + ': ' + this.y},
                        inside: true,
                        rotation: 270
                    },
                    pointPadding: 0.1,
                    groupPadding: 0
                }
            },

            series: [{
                data: [29.9, 71.5, 106.4, 129.2, 144.0, 176.0, 135.6, 148.5, 216.4, 194.1, 95.6, 54.4]
            }]
        });
    });

Upvotes: 23

jlbriggs
jlbriggs

Reputation: 17800

Really, what this case calls for, is for this to be a bar instead of a column, and category labels that are not rotated, and are clearly readable.

Example:

http://jsfiddle.net/jlbriggs/yPLVP/23/

You can also offset the axis labels to put category name on the bar itself, but really - it's just not as good a way to display as the above example:

http://jsfiddle.net/jlbriggs/yPLVP/24/

These could both be a column instead of a bar still, of course, but rotating the labels is always a bad idea if it can be avoided.

These methods also allow the data label to still be used as a data label should that ever be required.

Upvotes: 5

Related Questions