【问题标题】:Multiple labels in Highcharts Pie GraphHighcharts饼图中的多个标签
【发布时间】:2015-07-31 16:05:50
【问题描述】:

我有一个 Highcharts 饼图,我需要为每个切片显示多个标签,例如在切片外部带有连接器的指示符(标题)标签,以及在切片内部没有连接器的百分比标签。

我可以设置距离属性,以便将标签(和连接器)带到切片的内部,但是当然,外面不再有标签了。

任何帮助将不胜感激。 提前谢谢你。

【问题讨论】:

  • 您可以使用renderer 允许添加自定义文本/标签/路径。

标签: javascript highcharts


【解决方案1】:

无法直接创建多个数据标签。正如您在post 上看到的那样,解决方案是创建两个重叠图表。 见JSFiddle here

        $(function () {
            // Create the chart
            $('#container').highcharts({
                chart: {
                    type: 'pie',
                    backgroundColor: 'rgba(0,0,0,0)',
                    y:100

                },
                title: {
                    text: 'sfs '
                },
                yAxis: {
                    title: {
                        text: ' '
                    }
                },
                plotOptions: {
                    pie: {
//                        y:1,
                        shadow: false,
//                        center: ['50%', '50%'],
                        borderWidth: 0,
                        showInLegend: false,
                        size: '80%',
                        innerSize: '60%'
                      ,

                        data: [
                            ['allo', 18],
                            ['asdad', 14],
                            ['asdad', 11],
                            ['asdasd', 10],
                            ['adad', 8],
                            ['asdada', 7],
                            ['adada ada', 7],
                            ['adad', 5],
                            ['asdas',7],
                            ['ada', 3]

                        ]
                    }
                },
                tooltip: {
                    valueSuffix: '%'
                },
                series: [
                    {
                        type: 'pie',
                        name: 'Browser share',

                        dataLabels: {
                            color:'white',
                            distance: -20,
                            formatter: function () {
                                if(this.percentage!=0)  return Math.round(this.percentage)  + '%';

                            }
                        }
                    },
                    {
                        type: 'pie',
                        name: 'Browser share',

                        dataLabels: {
                            connectorColor: 'grey',
                            color:'black',
//                            y:-10,
                            softConnector: false,
                            connectorWidth:1,
                            verticalAlign:'top',
                            distance: 20,
                            formatter: function () {
                                if(this.percentage!=0)  return this.point.name;

                            }
                        }
                    }
                ]
            });
        });

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-08-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多