简体   繁体   English

Highcharts-如何获得名称以显示在饼形图中?

[英]Highcharts - How can I get the name to display in the pie wedges?

I've got a pie chart up and running and the client I'm doing it for is requesting the name, which appears in the tooltip hover, to be in the pie wedge so that when it's printed out the names appear. 我有一个饼图并正在运行,我正在为此做的客户端要求将名称(出现在工具提示悬停中)放在饼形楔中,以便在打印出名称时出现。 I have tried using a png to overlay the chart with no luck, tried distance: -60 and 我尝试使用png来覆盖图表,但是没有运气,尝试了distance: -60

dataLabels: {inside: true,}

but none of them respond. 但他们都没有回应。 I asked here yesterday and someone mentioned that there's a line in the highcharts-more.src.js file which reads: "Align column data labels outside the columns. #1199." 我昨天在这里问,有人提到在highcharts-more.src.js文件中有一行,内容为:“在列外对齐列数据标签。#1199。” - is there anyway I can specify in the following JS to have the data labels, or names in this case, appear in the pie slices? -无论如何,我可以在下面的JS中指定在饼图中显示数据标签或名称(在这种情况下为名称)吗?

JS: JS:

$(function () {

        $('#container').highcharts({

            chart: {
                polar: true
            },

            title: {
                text: 'Chart'
            },

            pane: {
                startAngle: 0,
                endAngle: 360

            },
            xAxis: {
                tickInterval: 45,
                min: 0,
                max: 360,
                labels: {
                    formatter: function () {
                        return;
                    }
                }
            },



            yAxis: {
                min: 0
            },

            plotOptions: {
                series: {
                    pointStart: 0,
                    pointInterval: 45,
                    dataLabels: {
                        inside: true,
                        offset: -100,
                        formatter: function() {
                            if(this.y !== 0) {
                                 return this.y.toFixed(1);   
                            }
                        }
                    }
                },
                column: {
                    grouping: false,
                    pointPadding: 0,
                    groupPadding: 0
                }
            },

            colors: [
                '#FFD700',
                '#458B00',
                '#0099CC'],

            series: [

            {
                type: 'column',
                name: 'Behaviour',
                shadow: true,
                data: [
                        {y:0},
                        {y:0},
                        {y:0},
                        {y: 78, name: 'Be Deliberate', inside: true}, 
                        {y: 82, name: 'Consistent, reliable', inside: true},
                        {y:0},
                        {y:0},
                        {y:0}
                    ],
                dataLabels: {                
                    enabled: true,
                    inside: true,
                    verticalAlign: 'top',
                    color: '#333333'
                }
            }, {
                type: 'column',
                name: 'Communication',
                shadow: true,
                data: [
                    {y:0},
                    {y:0},
                    {y:0},
                    {y:0},
                    {y:0},
                    {y: 80, name: 'Listen empathy'}, 
                    {y: 76, name: 'Communicate clear'},
                    {y: 88, name: 'Be honest transparent'}],
                dataLabels: {
                    enabled: true,
                    inside: true,
                    color: '#333333'
                }
            }, {
                type: 'column',
                name: 'Action',
                data: [
                        {y: 60, name: 'Act in clients best interests'}, 
                        {y: 70, name: 'Commit to do right thing'}, 
                        {y: 68, name: 'Deliver on promise'},
                        {y:0},
                        {y:0},
                        {y:0},
                        {y:0},
                        {y:0}
                    ],
                shadow: true,
                groupPadding: 0,
                pointPlacement: 'on',
                dataLabels: {
                    enabled: true,
                    inside: true,
                    distance: -60,
                    color: '#333333'
                }
            }]

        });
    });

HTML: HTML:

<div id="container" style="min-width: 810px; max-width: 900px; height: 900px; margin: 0 auto"></div>

Here's a fiddle , can anyone help? 这是一个小提琴 ,任何人都可以帮忙吗?

You had the correct location however your return was never including the text you need. 您的位置正确,但是return永远不会包含您需要的文字。 Try: 尝试:

dataLabels: {
    inside: true,
    offset: -100,
    formatter: function () {
        if (this.y !== 0) {
            return this.key + ' - ' + this.y.toFixed(1);
        }
    }
}

If you add return modification you will see the same text in the tooltip appear in the dataLabel...And you now also see how that is rather ugly given the length of the text you are trying to render. 如果添加return修改,您将在工具提示中看到相同的文本,出现在dataLabel中...并且现在您还可以看到,鉴于要呈现的文本长度,这是多么难看。 There are overlaps all over the place. 到处都有重叠。 You can try and mitigate this by having the dataLabels moved further out from the bar (it is a bar, not a pie wedge as this is a polar chart and not a pie chart). 您可以通过使dataLabels从条形图上进一步移开(它是条形图,而不是饼形图,因为这是极坐标图而不是饼图)来尝试缓解这种情况。 You can try and mess with the formatting more but I think this is going to get uglier fast. 您可以尝试弄乱格式,但我认为这将变得更加难看。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何在Kendo UI中的饼形图楔上获取标签 - How do I get labels on Pie Chart Wedges in Kendo UI 如何在Highcharts饼图中获取字体真棒图标的数据标签? - How can I get a data label in my Highcharts Pie Chart that is a font-awesome icon? 如何从HighCharts饼图中删除白色边框? - How can I remove the white border from HighCharts pie chart? 如何为Telerik Kendo UI饼图楔形着色? - How to color Telerik Kendo UI pie chart wedges? 如何在高图中显示for循环的结果 - How can I display the outcome of the for loop in highcharts 如何使用jquery Highcharts在饼图中显示值而不是百分比 - How to display the value instead of percentage in a pie chart using jquery Highcharts 如何让 Highcharts 的 yAxis 显示类别而不是数值? - How can I get the yAxis of Highcharts to display categories instead of number values? 如何在不从图例中删除饼图的情况下将饼图的切片隐藏在HighCharts中? - How Can I Hide a Pie Chart's Slice in HighCharts Without Removing It From the Legend? 如何仅从 csv 中提取特定列 \\ 单元格<pre>标记,进入highcharts饼图 - How can I pull only specific columns \ cells from csv in <pre> tag, into highcharts pie chart 如何获取ID作为值和名称以显示在dropdownlist php中 - How can I get the ID as value and Name to display in dropdownlist php
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM