2013-05-22 2 views
1

flot을 사용하여 매일 내 응용 프로그램이 가져 오는 검색 결과의 수를 보여주는 차트를 만들려고합니다. 내 코드 (BTW이 사용 underscore.js) :이 같은flot 날짜 막대 차트 정렬 비스듬히

flotDataSet = _.countBy(resultSet, function(file) { 
    var exactDate = new Date(parseInt(file.get('start_utc'), 10)); 

    //constructing a new date with 0 time so that all days get grouped together. 
    return new Date(exactDate.getUTCFullYear(), exactDate.getUTCMonth(), exactDate.getUTCDate()).getTime(); 
}); 

flotDataSet = _.map(flotDataSet, function(value, key) { 
    return [key, value]; 
}); 

$.plot(
    $graphDiv, 
    [{ 
     data: flotDataSet, 
     color: '#012D4C', 
     bars: { show: true, fillColor: '#024985', align: 'center', fill: 0.7, barWidth: DateUtil.msInDay/2 } 
    }], 
    { 
     grid: { color: '#012D4C' }, 
     xaxis: { 
      mode: 'time', 
      tickSize: [1, 'day'], 
      autoscaleMargin: 0.001 
     } 
    } 
); 

출력 뭔가 :

enter image description here

정말 일 중심으로하는 바이 필요합니다. 이견있는 사람? 감사!

+0

jsFiddle : http://jsfiddle.net/bUa3R/ – CullenJ

+0

이상합니다. 내 jsFiddle에서 작동하지만 내 웹 앱에서는 작동하지 않습니다. – CullenJ

답변

4

발견. JavaScript의 long-form Date(year, month, date [, time...]) 생성자가 현지 시간이나 이상한 것을 사용하기 때문에 내 Date 생성 코드가 꺼져 있습니다. 어쨌든, 나는 new Date(...).getTime()로 전화를 대체하여 Date.UTC(...)이되고 모든 것이 마술처럼 작동했습니다.

자바 스크립트처럼 보입니다. 날짜 처리가 JS 문제의 근원이되는 경향이 있습니다!

관련 문제