2017-01-21 6 views
1

C3의 두 선 차트에 x 축으로 시계열을 추가하려고합니다. 불행하게도 나는 그것을하는 방법을 알아낼 수 없다. 가능한 한 가깝게 C3의 timeseries 차트 예제를 따르려고했지만 "x = id"= "Dates"에 대해 정의되지 않은 오류를 제공합니다.C3 - 라인 차트 시계열 오류 : x = id "= 날짜"에 대해 정의되지 않았습니다.

다음은 코드입니까, 어떤 아이디어입니까?

request.addEventListener('readystatechange', function() { 
     if (this.readyState == 4) { 
      var throughputReceived = JSON.parse(this.responseText).throughputReceived, 
       throughputSent = JSON.parse(this.responseText).throughputSent, 
       date = JSON.parse(this.responseText).date, 
       chart, 
       length = throughputReceived.length; 

      for (var i = 0; i < length; i++) { 
       throughputReceived[i] /= 1000000; 
       throughputSent[i] /= 1000000; 
       //    date[i] = moment(date[i]).format("YYYY MM DD hh ss"); 
      } 

      throughputReceived.unshift('Throughput Received (Mbps)'); 
      throughputSent.unshift('Throughput Sent (Mbps)'); 
      date.unshift('Dates'); 

      chart = c3.generate({ 
       bindto: container, 
       data: { 
        x: date, 
        columns: [date, throughputReceived, throughputSent] 
       }, 
       axis: { 
        x: { 
         //      label: 'Test No.' 
         type: 'timeseries', 
         tick: { 
          format: '%Y %m %d %h %s' 
         } 
        }, 
        y: { 
         label: { 
          text: 'Throughput (Mbps)', 
          position: 'outer-top' 
         }, 
         tick: { 
          format: d3.format('.2f') 
         } 
        } 
       } 
      }); 
     } 
    }); 
+0

... – Mark

+0

죄송 같은 데이터가 어떻게 생겼는지 알 수없는이 질문에 대답하기 불가능 - '기간'필드 YYYY MM DD "에있을 moment.js에 의해 구문 분석되었습니다 날짜/시간 배열을 hh ss "형식이고 나머지 두 개는 숫자 배열입니다. 지금까지 'throughputReceived'및 'throughputSent'로 작업하는 그래프를 얻었으나 이제 그래프의 x 축으로 새 변수 'date'를 사용하고 싶습니다. – BenAdamson

답변

3

x 축을 잘못 정의했습니다.

날짜 배열을 참조하는 대신 열의 제목을 정의해야합니다.

date.unshift('Awesome-Column'); 
... 
data: { 
     x: 'Awesome-Column', 
     columns: [date, throughputReceived, throughputSent] 
     },