如何在Highcharts

时间:2016-06-07 12:24:02

标签: highcharts data-visualization pie-chart highcharts-ng

我正在使用Highcharts饼图,我想在饼图中有一个内圈。但是,在Highcharts中无法使用创建内圈的选项。

我想在我的图表中创建内圈,如下图所示:

enter image description here

以下是我的代码。我正在使用highcharts-ng.js。

var budget = 100;
var sectionVal = 56.33;

$scope.highchartsNGPie = {
    options: {
        chart: {
            plotBackgroundColor: null,
            plotBorderWidth: null,
            plotShadow: false,
            type: 'pie'
        },
        tooltip: {  
            enabled: false,
        },  
        pane: {
            startAngle: 0,
            endAngle: 360,
            background: [{ // Track for Move
                outerRadius: '98%',
                innerRadius: '88%',
                backgroundColor: Highcharts.Color('#808080').setOpacity(0.3).get(),
                borderWidth: 0
            }]
        },
        plotOptions: {
                pie: {
                    allowPointSelect: false,        //to stop animation of section
                    cursor: 'default',                   
                    borderWidth: 0,
                    showInLegend: false             
                },
                series: {
                    animation: false,
                }
        },
    },
    series: [{
        name: 'spent',
        colorByPoint: true,
        states: {
            hover: {
                enabled: false
            }
        },
        data: [{
            name: 'Spent',
            y: sectionVal,
            color: '#50B432',
            tooltipDisabled: false,
            dataLabels: {
                style: {
                    color: 'black'
                },
                enabled: true,
                formatter: function () {
                    //return (this.axis.series[1].yData[this.x] / this.total * 100).toPrecision(2) + '%';
                    return this.point.y + "%";
                }
            },
        }, {
            y: budget - sectionVal,
            sliced: true,
            selected: true,
            color: '#ffffff',
            tooltipDisabled: true,
            dataLabels: {
                enabled: false
            },

        }]
    }],
    title: {
        text: 'Your Budget for September',
        align: 'top'

    },
    loading: false
}

<div highchart id="chart1" config="highchartsNGPie"></div>

1 个答案:

答案 0 :(得分:0)

您可以使用sizeinnerSize选项使用它。

// Build the chart
Highcharts.chart('container', {
    chart: {
        plotBackgroundColor: null,
        plotBorderWidth: null,
        plotShadow: false,
        type: 'pie'
    },
    title: {
        text: 'Browser market shares in January, 2018'
    },
    tooltip: {
        pointFormat: '{series.name}: <b>{point.percentage:.1f}%</b>'
    },
    plotOptions: {
        pie: {
            allowPointSelect: true,
            cursor: 'pointer',
            dataLabels: {
                enabled: false
            },
            showInLegend: true
        }
    },
    series: [{
        name: 'Brands',
        colorByPoint: true,
        innerSize: '50%',
        data: [{
            name: 'Chrome',
            y: 61.41,
            sliced: true,
            selected: true
        }, {
            name: 'Internet Explorer',
            y: 11.84
        }, {
            name: 'Firefox',
            y: 10.85
        }, {
            name: 'Edge',
            y: 4.67
        }, {
            name: 'Safari',
            y: 4.18
        }, {
            name: 'Other',
            y: 7.05
        }]
    }]
});
<script src="https://code.jquery.com/jquery-3.1.1.min.js"></script>
<script src="https://code.highcharts.com/highcharts.js"></script>
<script src="https://code.highcharts.com/modules/exporting.js"></script>
<script src="https://code.highcharts.com/modules/export-data.js"></script>

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