2

我在 highcharts JSFiddle中使用组合图表。超过某个点,饼图会妨碍折线图的显示并阻碍其可见性。

如何根据折线图的值动态上/下推饼图。

这是我的highcharts代码。

$(function () {
        $('#container').highcharts({
            chart: {
            },
            title: {
                text: 'Combination chart'
            },
            xAxis: {
                categories: ['Apples', 'Oranges', 'Pears', 'Bananas', 'Plums']
            },
            tooltip: {
                formatter: function() {
                    var s;
                    if (this.point.name) { // the pie chart
                        s = ''+
                            this.point.name +': '+ this.y +' fruits';
                    } else {
                        s = ''+
                            this.x  +': '+ this.y;
                    }
                    return s;
                }
            },
            labels: {
                items: [{
                    html: 'Total fruit consumption',
                    style: {
                        left: '40px',
                        top: '8px',
                        color: 'black'
                    }
                }]
            },
            series: [{
                type: 'spline',
                name: 'Average',
                data: [3, 6, 3, 6.33, 3.33],
                marker: {
                    lineWidth: 2,
                    lineColor: Highcharts.getOptions().colors[3],
                    fillColor: 'white'
                }
            }, {
                type: 'pie',
                name: 'Total consumption',
                data: [{
                    name: 'Jane',
                    y: 13,
                    color: Highcharts.getOptions().colors[0] // Jane's color
                }, {
                    name: 'John',
                    y: 23,
                    color: Highcharts.getOptions().colors[1] // John's color
                }, {
                    name: 'Joe',
                    y: 19,
                    color: Highcharts.getOptions().colors[2] // Joe's color
                }],
                center: [100, 80],
                size: 100,
                showInLegend: false,
                dataLabels: {
                    enabled: false
                }
            }]
        });
    });

我想要这样东西。您会看到饼图和样条曲线没有冲突。但在我的例子中,样条的价值很高,饼图阻碍了样条的可见性。饼图应在样条曲线上方或下方的某个位置自动调整。

我怎样才能做到这一点?

4

1 回答 1

1

我认为没有自动的方法。您可能需要添加一些逻辑来设置图表的中心和大小参数,具体取决于所绘制的数据。

另一种方法是延长 y 轴以腾出空间。您可以根据绘制的最大值加上饼图的足够空间来计算:

 yAxis: {
            max:10
        },

http://jsfiddle.net/Y7GMr/

于 2013-10-24T08:07:21.373 回答