2014-10-30 2 views
1

인 yAxis에 시리즈 추가하기 highcharts에서 다른 ID를 사용하여 yAxis에 시리즈를 추가하는 데 몇 가지 문제가 있습니다. 내가 예를 만들었HighCharts. ID가

:

$(function() { 

     $('#graf').highcharts({ 
      chart: { 
       zoomType: 'xy' 
      }, 
      title: { 
       text: '' 
      }, 
      subtitle: { 
       text: '' 
      }, 
      xAxis: [{type: 'datetime', 
        title: { 
         text: 'Date' 
        }}], 
      yAxis: [], 
        series : [] 
        , 
      tooltip: { 
       shared: true 
      }, 
      legend: { 
       enabled: true, 
       align: 'left', 
       backgroundColor: '#FFFFFF', 
       borderColor: 'grey', 
       borderWidth: 1, 
       layout: 'vertical', 
       verticalAlign: 'top', 
       y: 0, 
       shadow: true 
      } 
     }); 


var chart = $('#graf').highcharts(); 
$('#add').click(function() { 
    chart.addAxis({ // Secondary yAxis 
     id: "asd", 
     title: { 
      text: 'Rainfall' 
     }, 
     lineWidth: 2, 
     lineColor: '#08F', 
     opposite: true 
    });  
    chart.addAxis({ // Secondary yAxis 
     id: "abc", 
     title: { 
      text: 'Rainfall' 
     }, 
     lineWidth: 2, 
     lineColor: '#08F', 
     opposite: true 
    });  
    chart.addSeries({ 
     name: 'Rainfall', 
     type: 'column', 
     color: '#08F', 
     yAxis: "asd", 
     data: [ [Date.UTC(1970, 9, 27), 0 ], 
      [Date.UTC(1970, 10, 10), 0.6 ], 
      [Date.UTC(1970, 10, 18), 0.7 ], 
      [Date.UTC(1970, 11, 2), 0.8 ], 
      [Date.UTC(1970, 11, 9), 0.6 ]] 
    }); 
    $(this).attr('disabled', true); 
    $('#remove').attr('disabled', false); 
}); 
}); 

JSFIDDLE : http://jsfiddle.net/5f6b6mu9/

나는 ID가 "ASD"와 "ABC"와 y 축이있다. "asd"yAxis에 시리즈를 추가하려고하면 작동하지 않습니다. 잡히지 않은 TypeError : '길이'가 정의되지 않은 속성을 읽을 수 없습니다. 여기

내 웹 페이지에서 세드릭의 모자입니다 : http://i61.tinypic.com/8yx7cw.jpg

내가 동일한 ID로 두 y 축 ID를 변경하는 경우, 그것은 작동하지만 요점을 이잖아 없습니다.

제안 사항? 감사합니다

답변

1

아주 간단합니다.

시리즈를 추가 한 직후 yAxis에 해당하는 시리즈를 추가하십시오.

chart.addAxis({ // Secondary yAxis 
      id: "asd", 
      title: { 
       text: 'Rainfall' 
      }, 
      lineWidth: 2, 
      lineColor: '#08F', 
      opposite: true 
     },false); 
     chart.addSeries({ 
      name: 'Rainfall', 
      type: 'column', 
      color: '#08F', 
      yAxis: "asd", 
      data: [ [Date.UTC(1970, 9, 27), 0 ], 
       [Date.UTC(1970, 10, 10), 0.6 ], 
       [Date.UTC(1970, 10, 18), 0.7 ], 
       [Date.UTC(1970, 11, 2), 0.8 ], 
       [Date.UTC(1970, 11, 9), 0.6 ]] 
     }); 

     chart.addAxis({ // Secondary yAxis 
      id: "abc", 
      title: { 
       text: 'Rainfall' 
      }, 
      lineWidth: 2, 
      lineColor: '#08F', 
      opposite: true 
     },false); 

여기에 내가 업데이 트했습니다 당신의 fiddle

+0

내가 캔트 내 시리즈는 XMLHttpRequests를 동적으로로드 때문. 어쨌든, 다음과 같이 수정했습니다. 차트를 만든 다음 chart.addaxis와 함께 yAxis를 추가하는 대신 Yaxis가있는 차트를 직접로드했습니다. ..... xAxis : [{type : 'datetime', 제목 : { 텍스트 : '날짜' }}], y 축 : 여기 내 동적로드 AXIS, 시리즈 : [] ..... 내가 처음에 축을 얻을 수 있기 때문에이 작동 .. otherway 그것은 작동하지 않습니다. 어쨌든 고마워! 내 영어로 미안해. – Fabricio