40

我一直在寻找使用 Highcharts 库生成最简单的圆环图的解决方案。但是,Highcharts 的所有示例都显示了内馅饼和外甜甜圈的图表样式(参考:http ://www.highcharts.com/demo/pie-donut )

我怎样才能摆脱内部馅饼而只保留外部甜甜圈,就像其他图书馆一样?(类似于 RGraph:https ://www.rgraph.net/demos/donut-3d.html )

谢谢你。

4

3 回答 3

100

您只需将数据作为两个元素(键/值)数组的数组提供。指定 aninnerSize以获取甜甜圈样式。

因此,您的参数将包含如下内容:

...
data: [["Firefox",6],["MSIE",4],["Chrome",7]],
innerSize: '20%',
...

这是一个完整示例的 jsFiddle

于 2012-07-26T22:35:31.803 回答
2
**I hope this example of highchat will solve your problum

http://jsfiddle.net/e2qpa/3/

$(function() {
    var chart = new Highcharts.Chart({
        chart: {
            renderTo: 'container',
            type: 'pie'
        },

        plotOptions: {
            pie: {
                borderColor: '#000000',
                innerSize: '60%'
            }
        },
        series: [{
            data: [
                ['Firefox', 44.2],
                ['IE7', 26.6],
                ['IE6', 20],
                ['Chrome', 3.1],
                ['Other', 5.4]
                ]}]
    },
    // using

    function(chart) { // on complete

        var xpos = '50%';
        var ypos = '53%';
        var circleradius = 102;

    // Render the circle
    chart.renderer.circle(xpos, ypos, circleradius).attr({
        fill: '#ddd',
    }).add();

    // Render the text
    chart.renderer.text('THIS TEXT <span style="color: red">should be in the center of the donut</span>', 155, 215).css({
            width: circleradius*2,
            color: '#4572A7',
            fontSize: '16px',
            textAlign: 'center'
      }).attr({
            // why doesn't zIndex get the text in front of the chart?
            zIndex: 999
        }).add();
    });
});
于 2012-12-07T05:51:27.043 回答
1

这是最热门的搜索结果,给出的答案对我不起作用。我需要对数据点进行更多控制,而不仅仅是一个简单的数组。我需要使用 JSON 对象来配置其他选项,例如特定数据的显式颜色。我通过一些研究发现您根本不需要修改数据格式。要将饼图制作成圆环图,您只需在数据系列中设置大于 0 的 innerSize 值即可。

从 highcharts 文档中:

innerSize:饼图的内径大小。大于 0 的大小会呈现圆环图。可以是百分比或像素值。百分比与饼图大小相关。像素值以整数形式给出。

因此,您可以获得一个简单的圆环图,其数据如下:

        series: [{
            innerSize: '30%',
            data: [
                {name: 'Yellow Slice', y: 12, color: 'yellow'},
                {name: 'Red Slice', y: 10, color: 'red' },
                {name: 'Blue Slice', y: 33, color: 'blue'},
                {name: 'Green Slice', y: 20, color: 'green'}
            ]
        }]

JS小提琴

于 2017-02-26T20:29:52.023 回答