简体   繁体   English

高图-防止饼图与折线图重叠?

[英]Highcharts - prevent pie chart from overlaping a line chart?

I have two-in-one charts, as you can see here: 我有二合一图表,您可以在此处看到:

http://jsfiddle.net/8ankuh8s/ http://jsfiddle.net/8ankuh8s/

$('#container').highcharts({
    xAxis: {
        categories: ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'],
        tickInterval: 1,
        tickmarkPlacement: "on",
        startOnTick: true,
        endOnTick: true,
        minPadding: 0,
        maxPadding: 0,
        offset: 0
    },

    series: [{
        data: [190.9, 180.5, 106.4, 129.2, 144.0, 176.0, 135.6, 148.5, 216.4, 194.1, 95.6, 54.4]
    }, {
        type: 'pie',
        data: [29.9, 71.5, 150],
        center: [50, 40],
        dataLabels: {
            enabled: false
        },
        size: 100
    }]
});

}); });

You'll see that pie chart overlaps the line chart. 您会看到饼图与折线图重叠。

I want to achieve the following result (mock): 我想获得以下结果(模拟):

在此处输入图片说明

I tried to do this with offset parameter on xAxis , but it's not working as expected. 我尝试使用xAxis上的offset参数来执行此操作,但是它没有按预期工作。

I think that in case of your chart you can use xAxis.min and xAxis.tickPositioner. 我认为,在您的图表中,可以使用xAxis.min和xAxis.tickPositioner。 You can find information about them inside API: http://api.highcharts.com/highcharts#xAxis.min http://api.highcharts.com/highcharts#xAxis.tickPositioner 您可以在API中找到有关它们的信息: http : //api.highcharts.com/highcharts#xAxis.min http://api.highcharts.com/highcharts#xAxis.tickPositioner

You can use them to move your categories on your xAxis. 您可以使用它们在xAxis上移动类别。 Here you can find code that can help you: 在这里,您可以找到有助于您的代码:

    xAxis: {
  categories: ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'],
  tickmarkPlacement: "on",
  minPadding: 0,
  maxPadding: 0,
  min: -5,
  tickPositioner: function() {
    var positions = [];
    for (var i = 0; i < this.categories.length; i++) {
      positions.push(i)
    }
    return positions
  }
},

With this function I will show only your categories on xAxis, but they will be shifted with xAxis.min parameter. 使用此功能,我将仅在xAxis上显示您的类别,但是它们将通过xAxis.min参数移动。

Here you can find an example how it can work: http://jsfiddle.net/8ankuh8s/2/ 在这里,您可以找到一个示例它如何工作的: http : //jsfiddle.net/8ankuh8s/2/

Best regards. 最好的祝福。

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM