将y轴固定为0高图

时间:2017-03-01 14:31:40

标签: highcharts fixed yaxis

我试图制作一个具有负值和正值的高图。现在的情况是,与正面值相比,负值并不是很大。

这是图表的图片: graph

现在,如果仔细观察两个y轴,它们在0处不会相遇,则存在微小的差距。是否有可能使它们从0开始,但允许它们为负?

这是我的代码:

Highcharts.chart('chart', {
                chart: {
                    type: 'column'
                },
                title: {
                    text: 'Sales Graph'
                },
                xAxis: {
                    categories: xAxisTicks
                },
                plotOptions: {
                    column: {
                        stacking: 'normal'
                    }
                },
                tooltip: {
                    formatter: function() {
                        debugger;
                        if (this.series.type == "column") {
                            return '<b>' + this.x + '</b><br/>' +
                                this.series.name + ': ' + prettyNumber(this.y) + '<br/>' +
                                'Sales without discount: ' + prettyNumber(this.point.stackTotal);
                        } else {
                            return '<b>' + this.x + '</b><br/>' +
                                this.series.name + ': ' + prettyNumber(this.y) + '<br/>';
                        }
                    }
                },
                colors: ['yellow', 'orange', 'red', 'blue', 'green', 'red', 'blue', 'green'],
                yAxis: [
                {
                    title: {
                        text: 'Daily sales'
                    },
                    min: minYAxisValue,
                    startOnTick: false
                }, {
                    title: {
                        text: 'Accumulated sales'
                    },
                    min: minYAxisValue,
                    startOnTick: false,
                    opposite: true
                }
                ],
                series: data
            });

1 个答案:

答案 0 :(得分:0)

如果你想要两个对齐0勾在一起,这是高图无法实现的。请遵循此讨论https://highcharts.uservoice.com/forums/55896-general/suggestions/2554384-multiple-axis-alignment-control?page=3&per_page=20

但是,您可以尝试这个简单的解决方法:

在两个y轴上都有固定的最小值/最大值:

yAxis: [{ min: minYAxisValue, max: maxYAxisValue }

或者只是将第二个轴链接到第一个轴:

yAxis: [{ opposite: true, linkedTo: 0 }
相关问题