2014-12-26 8 views
0

이렇게하면 데이터를 작성할 수 있습니까?C3js : 각 라인의 맞춤 날짜

['2013-01-01', 'redline', 120], 
['2013-01-02', 'greenline', 160], 
['2013-01-02', 'blueline', 200], 
['2013-01-04', 'greenline', 160], 

"n"개의 다른 라인이 있으며 각각 다른 날짜가 있습니다 ... 어떻게 C3js로 그릴 수 있습니까?

enter image description here

가하는 multiple x chart in c3js 사용하려면 여러 XS 값을 선언해야합니다 : 정말 매우

+0

각 색상별로 여러 날짜가 있습니까? 또는 라인 - 당신은 그것을 보면서. \ – Todd

+0

또한, 당신이 원한다면 더 구체적 일 수 있습니까? – Todd

+0

나는 timeseries 차트를 만들 필요가있다. http://jsfiddle.net/gh/get/jquery/1.9.1/highslide-software/highcharts.com/tree/master/samples/highcharts/demo/spline-irregular- 시각/. 여기에 각 행의 날짜/값을 설정할 수 있습니다. '이름 '블루 라인', 데이터 : [ [중 Date.UTC (1970, 9, 27), 0]},' 어떻게이 c3js로 할 수있는 ? – wpanin

답변

1

는 당신이 필요로하는 것은이 같은 복수의 X 축과 선형 차트, 어떤 도움을 appresiate 될 것입니다.

여기에 날짜를 추가해야 할 것 같아서 데이터와 날짜가 포함 된 배열을 전역으로 만들었습니다.

하단의 기능은 새로운 날짜와 데이터를 배열에 푸시합니다.

이러한 변수를 c3js로로드하려면 concat 함수를 사용하십시오.

//Declare three x axes, and a dataset for each axis. 
var periodOne = ['2013-01-01', '2013-01-04', '2013-01-07','2013-01-11','2013-01-15']; 
var periodTwo = ['2013-01-02', '2013-01-04', '2013-01-06','2013-01-08', '2013-01-10','2013-01-13', '2013-01-15','2013-01-18', '2013-01-22']; 
var periodThr = ['2013-01-05', '2013-01-10', '2013-01-15','2013-01-20', '2013-01-25']; 
var xOne = [12,31,14,13,34]; 
var xTwo = [11,13,14,23,63,27,21,19,15]; 
var xThr = [12,32,13,13,23]; 

var chart = c3.generate({ 
     data: { 
      xs:{ 
       //Declare the axes 
       'Winter 08,09': 'x1', 
       'Winter 09,10': 'x2', 
       'Winter 10,11': 'x3' 
      }, 
      columns: [ 
       ['x1'].concat(periodOne), 
       ['x2'].concat(periodTwo), 
       ['x3'].concat(periodThr), 
       ['Winter 08,09'].concat(xOne), 
       ['Winter 09,10'].concat(xTwo), 
       ['Winter 10,11'].concat(xThr) 
      ] 
     }, 
     axis: { 
      x: { 
       type: 'timeseries' 
      } 
     } 
    }); 
//You don't need this for multiple x axes, it's just to push data to arrays 
function push(oneValue, oneDate, twoValue, twoDate, thrValue, thrDate){ 
    periodOne[periodOne.length] = oneDate; 
    xOne[xOne.length] = oneValue; 
    periodTwo[periodTwo.length] = twoDate; 
    xTwo[xTwo.length] = twoValue; 
    periodThr[periodThr.length] = thrDate; 
    xThr[xThr.length] = thrValue; 
    chart.load({ 
     columns: [ 
      ['x1'].concat(periodOne), 
      ['x2'].concat(periodTwo), 
      ['x3'].concat(periodThr), 
      ['Winter 08,09'].concat(xOne), 
      ['Winter 09,10'].concat(xTwo), 
      ['Winter 10,11'].concat(xThr) 
     ] 
    }); 
} 
//Use this function to push new data 
push(13, '2013-01-19', 23, '2013-01-24', 17, '2013-01-30'); 
+0

감사합니다 !!! 그것은 위대한 작품. 최대 축 값을 45에서 43으로 설정하는 방법을 알고 있습니까? – wpanin

+0

축 범위 설정은 http://c3js.org/samples/api_axis_range.html에서이 방법으로 수행 할 수 있습니다. http://c3js.org/samples/axes_y_range.html – JasTonAChair