0
我試圖做響應圖表...我用這個,但它沒有響應,只是當我刷新頁面縮放到正確的寬度...然後我有任何其他的想法?響應圖表
,我嘗試設置與viewBox
和preserveAspectRatio
。但同樣的結果div
..
var graph = new Rickshaw.Graph({
element: document.querySelector("#chart"),
height: 100,
series: [{
color: '#1abc9c',
data: [
{ x: 0, y: 50 },
{ x: 1, y: 50 },
{ x: 2, y: 40 },
{ x: 3, y: 40 },
{ x: 4, y: 30 },
{ x: 5, y: 20 },
{ x: 6, y: 0 },
{ x: 7, y: 0 } ]
}]
});
graph.render();
var svg = d3.select('.chart-container').append("svg")
.attr("width", '100%')
.attr("height", '100%')
.attr('viewBox','0 0 '+Math.min(width,height)+' '+Math.min(width,height))
.attr('preserveAspectRatio','xMinYMin')
.append("g")
.attr("transform", "translate(" + Math.min(width,height)/2 + "," + Math.min(width,height)/2 + ")");
<div class="chart-container" id="chart"></div>
這裏有一個調整大小的例子:https://github.com/shutterstock/rickshaw/blob/master/examples/resize.html –
謝謝它真的節省我的時間來找到解決方案! – liborza