2014-09-24 34 views
1

我面臨工具提示在x軸上顯示日期的問題。 任何人都可以幫忙嗎?用於日期格式的flotchart上的工具提示問題

fiddle code

  grid: { 
       hoverable: true //IMPORTANT! this is needed for tooltip to work 
      }, 
      tooltip: true, 
      tooltipOpts: { 
       content: "<h4>%s</h4><ul><li>Date is %x</li><li>Total Count: %y</li></ul>",   
      defaultTheme: false 
     }, 
     points: 
     { 
       show: true 
     }, 
     series: { 

      bars: { 
       show: true, 
       barWidth: 0.1, 
       order: 1 
      } 
     } 

回答

5

你需要一個函數的x值(這僅僅是一個數/時間戳)轉換爲實際日期。

使用這樣的事情:

tooltipOpts: { 
    content: function (label, x, y) { 
     var date = new Date(+x); 
     var tooltip = '<h4>' + label + '</h4><ul>'; 
     tooltip += '<li>Date is ' + date.toLocaleDateString() + '</li>'; 
     tooltip += '<li>Total Count: ' + y + '</li></ul>'; 
     return tooltip; 
    }, 

看到這個更新fiddle

+1

@ user416,如果您需要更高級的日期格式,flot會暴露'$ .plot.formatDate'函數。 – Mark 2014-09-25 13:01:59