2017-01-06 66 views
0

即使關聯的軸有visible: false,是否有方法顯示繪圖?隱藏軸似乎也隱藏了情節。用隱藏軸顯示高位地圖的情節線?

更多詳細信息...

我畫了一天的圖,像這樣:

enter image description here

我只是想增加在特定時間的垂直線,線「現在」時間等

如果我這樣做,用的情節線,則軸顯示了太多:

enter image description here

我絕對不希望軸顯示。

我現在的計劃是使用render.rectrender.path在圖表上繪製我自己的線。還有其他選擇嗎?

+1

正確 - 繪圖線是座標軸的子節點,隱藏軸時隱藏。如果您可以設置一個小提琴或代碼示例,以及關於您想要實現的更多信息,我相信我們可以找到一種方法來解決它。 – jlbriggs

+0

這太糟糕了。我會在接下來的幾天看看我能不能設置一些東西。 –

+0

你會期望它做什麼?情節線位於沿着該軸的特定點處。如果軸不在那裏,那麼線應該繪製在哪裏?圖表如何知道?我想如果你詳細說明爲什麼你想要這種行爲,我們很快就會發現有更好的方法來獲得你所需要的。 – jlbriggs

回答

1

我找到了一個相對平凡解...只是用CSS隱藏:

.highcharts-xaxis { 
    display: none; 
} 

和JS:

xAxis: { 
    type: 'datetime', 
    labels:{ 
     enabled: false 
    } 
} 

enter image description here

+1

是的,這是要走的路。或者,如果您想在javascript中完成所有操作,或者對於具有較舊版本的Highcharts的用戶,您可以在'xAxis'中添加'lineWidth:0'。 – jlbriggs

0

您可以通過包裝負責重繪軸的方法extend Highcharts

Highcharts.wrap(Highcharts.Axis.prototype, 'redraw', function(p) { 
p.call(this); 
console.log(this); 
var axis = this, 
    each = Highcharts.each, 
    options = this.options; 
// move plot lines and bands 
if (!axis._addedPlotLB) { // only first time 
    each((options.plotLines || []), function(plotLineOptions) { 
    axis.addPlotBandOrLine(plotLineOptions); 
    }); 
    axis._addedPlotLB = true; 
} 

each(this.plotLinesAndBands, function(plotLine) { 
    plotLine.render(); 
}); 
}); 

例如:http://jsfiddle.net/ncs81btt/

上面的解決方案是不是很優雅,雖然。更好的方法是使用Renderer或隱藏特定的軸元素(標籤,刻度等)。

根據你需要的情節線功能,使用渲染器需要做一些計算。

var customPlotLines = [{ 
    value: 5, 
    color: 'red', 
    width: 3 
    }, { 
    value: 10, 
    color: 'yellow', 
    width: 3 
    }] 

function renderPlotLines() { 
var axis = this.xAxis[0], 
    top = axis.chart.plotTop, 
    bottom = top + axis.chart.plotHeight, 
    path = [ 
     'M', null, top, 
     'L', null, bottom 
    ]; 

if (!this.customPlotLines) { 
    this.customPlotLines = customPlotLines.map(plotLine => { 
    return this.renderer.path([]).add(); 
    }); 
} 

this.customPlotLines.forEach((plotLine, i) => { 
    var opt = customPlotLines[i]; 
    path[4] = path[1] = axis.toPixels(opt.value); 
    plotLine.attr({ 
    d: path.join(' '), 
    'stroke-width': opt.width, 
    stroke: opt.color 
    }); 
}); 
} 

掛鉤加載/重繪事件,所以元素將調整大小。

chart: { 
    zoomType: 'xy', 
    events: { 
    load: renderPlotLines, 
    redraw: renderPlotLines 
    } 
}, 

例如:http://jsfiddle.net/ncs81btt/1/