2016-01-02 33 views
0

爲什麼當我將鼠標懸停在點上時,canvas.js圖表的工具提示顯示「12:00 AM:0.0645840023」?Canvas.js在寬度拉伸時顯示12AM(奇怪的錯誤)

的jsfiddle:http://jsfiddle.net/ssjqoa64/2/

如果我展開容器/窗寬它顯示12AM錯誤。非常奇怪的錯誤。

它應該顯示日期。

window.onload=function() { 
    CanvasJS.addColorSet("colset", ["#337ab7"]); 
    var chart=new CanvasJS.Chart("chartContainer", { 
     colorSet: "colset", backgroundColor: "#f5f5f5", zoomEnabled: true, exportEnabled: true, exportFileName: "Earnings Chart", axisX: { 
      labelFontFamily: "tahoma" 
     } 
     , axisY: { 
      labelFontFamily: "tahoma", 
     } 
     , data: [ { 
      type: "area", dataPoints: [ { 
       x: new Date(2015, 12, 29), y: 0.016440000385046 
      } 
      , { 
       x: new Date(2015, 12, 30), y: 0.064584002396259 
      } 
      , { 
       x: new Date(2015, 12, 31), y: 0.0098100002505817 
      } 
      , { 
       x: new Date(2016, 1, 1), y: 0.34803301144257 
      } 
      , { 
       x: new Date(2016, 1, 2), y: 0.20135760693211 
      } 
      , ] 
     } 
     ] 
    } 
    ); 
    chart.render(); 
} 
+2

在猜測,可能是因爲因爲沒有指定小時,分鐘或秒指定的日期將默認爲上午12:00?當x軸從日期變爲時間時,它可能使用時間戳? – JosephGarrone

+0

我同意,我認爲那將是。 – Sam

+0

我會尋找正確的答案,但我想我會去與http://www.chartjs.org相反;/ –

回答

1

它看起來當xAxis正在改變爲更小的粒度等(IE:從日期更改爲倍)工具提示格式變化相匹配。

解決方案是根據documentation使用自定義工具提示功能。

請在this fiddle找到一個工作解決方案。

新的JavaScript:

CanvasJS.addColorSet("colset", ["#337ab7"]); 
var chart=new CanvasJS.Chart("chartContainer", { 
    colorSet: "colset", backgroundColor: "#f5f5f5", zoomEnabled: true, exportEnabled: true, exportFileName: "Earnings Chart", axisX: { 
     labelFontFamily: "tahoma" 
    } 
    , toolTip: { // THIS IS NEW 
     contentFormatter: function(e) { 
      var date = e.entries[0].dataPoint.x; 
      var value = e.entries[0].dataPoint.y; 
      return CanvasJS.formatDate(date, "MMM DD YYYY") + ": " + value; 
     } 
    } // END OF NEW 
    , axisY: { 
     labelFontFamily: "tahoma" 
    } 
    , data: [ { 
     type: "area", dataPoints: [ { 
      x: new Date(2015, 12, 29), y: 0.02 
     } 
     , { 
      x: new Date(2015, 12, 30), y: 0.06 
     } 
     , { 
      x: new Date(2015, 12, 31), y: 0.01 
     } 
     , { 
      x: new Date(2016, 1, 1), y: 0.35 
     } 
     , { 
      x: new Date(2016, 1, 2), y: 0.21 
     } 
     , ] 
    } 
    ] 
} 

); 
chart.render(); 
+0

很好地完成,謝謝! –