Highcharts:使X和Y轴相交为0

我试图让我的图表的X轴和Y轴始终相交为0。 目前,我正在拦截’load’事件,然后更改最初工作的轴的偏移,但是当调整窗口大小或放大图表时,轴不会更新。

即使调整窗口大小或图表缩放,如何将轴保持在0的中心位置?

这是我的小提琴和代码: http : //jsfiddle.net/a003mc4b/

$(function () { $('#container').highcharts({ chart: { type: 'scatter', zoomType: 'xy', events: { load : function() { this.xAxis[0].update({ offset: -this.yAxis[0].translate(0) }); this.yAxis[0].update({ offset: -this.xAxis[0].translate(0) }); } }, }, title: { text: 'X and Y axis should intersect at 0' }, yAxis: { lineColor: '#FF0000', lineWidth: 1 }, xAxis: { lineColor: '#FF0000', lineWidth: 1 }, series: [{ data: [[0,0],[1,1],[2,5],[-1,-5],[0,5]] }] }); }); 

你可以使用情节线的概念。

你可以为xAxis和Yaxis绘制一条线,即使你resize也会使它们相交为0

 xAxis: [{ plotLines: [{ value: 0, width: 2, color: 'blue' }] }], yAxis : [{ plotLines: [{ value: 0, width: 2, color: 'blue' }] }] 

在这里更新你的js小提琴,

即使你resize,这件事也不会受到影响。

尝试这样的事情:

 yAxis: { offset: -15 }, 

检查这个小提琴: http : //jsfiddle.net/a003mc4b/2/

Interesting Posts