javascript HighCharts 在条形图上放置标签

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/17698955/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-27 09:15:40  来源:igfitidea点击:

HighCharts Place Label on Bar

javascriptjqueryhtmlhighcharts

提问by Wjdavis5

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?

鉴于下面的图像 - 我想从每列的图例中获取标签并将其打印在列本身上。我无法在 HighCharts API 中找到任何允许我执行此操作的内容。有没有人有任何想法或例子,我可以看看?

Thank you!

谢谢!

HighChart Exampl

HighChart 示例

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.

我认为这很容易辨别。用例是这些统计数据显示在呼叫中心周围的大型监视器上。图例通常太小,无法从任何给定距离读取。

回答by GGG

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]
            }]
        });
    });

回答by jlbriggs

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/

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/

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.

如果需要,这些方法还允许数据标签仍用作数据标签。