2015-01-23 2 views
1

내 차트에 눈금 효과를 렌더링하기 위해 내 축의 눈금 크기 조정 방법을 사용하고 있습니다. 내가 가진 문제는 차트의 너비가 윈도우 크기 변경으로 인해 변경 될 때 y 축에서 틱의 크기를 조정하는 법을 배울 수 없다는 것입니다. 차트의 크기를 변경했을 경우차트 크기를 조정할 때 틱 크기 수정

this._xRange = d3.time.scale().range([0, chartWidth]); 
    this._yRange = d3.scale.linear().range([chartHeight, 0]); 
    this._xAxis = d3.svg.axis().scale(this._xRange) 
    .orient("bottom") 
    .tickSize(-chartHeight) 
    .tickSubdivide(true); 
    this._yAxis = d3.svg.axis().scale(this._yRange) 
    .orient("left") 
    .tickSize(-chartWidth) 
    .tickSubdivide(true); 

, 나는 차트의 폭과 높이를 재 계산하고 축을 다시 그리기를 시도하고 다음과 같이 내 차트를 초기화해야

코드입니다. 이 브라우저 콘솔에서 다음과 같은 예외와 함께 실패

// Redraw the y axis 
    this._yAxis = d3.svg.axis().scale(this._yRange) 
    .orient("left") 
    .tickSize(-chartWidth) 
    .tickSubdivide(true); 
    this._chart.call(this._yAxis.orient("left")); 

:

DOMException: Failed to execute 'insertBefore' on 'Node': The node before 
which the new node is to be inserted is not a child of this node. "Error: 
Failed to execute 'insertBefore' on 'Node': The node before which the new 
node is to be inserted is not a child of this node. 

답변

0

나는 해결책에 명중했다고 생각 y 축 위해 나는 다음과 같은 코드를 사용하고 있습니다. 기존 y 축을 제거하고 새 생성기를 만든 다음 새 생성기를 차트에 추가해야합니다. 이렇게하려면 다음 코드를 사용하고 있습니다.

d3.select(".y.ResourceStatsAxis").remove(); 
    this._yAxis = d3.svg.axis().scale(this._yRange) 
    .orient("left") 
    .tickSize(-chartWidth) 
    .tickSubdivide(true); 
    this._chart.append("g") 
    .attr("class", "y ResourceStatsAxis") 
    .call(this._yAxis); 
관련 문제