2014-07-14 20 views
3

我正在使用morris圖表。在x軸上,我顯示了一個日期。一切都很好,除了標籤。我想顯示我的標籤,如x軸格式。如何將綠色圓圈的值更改爲紅色圓圈的值格式?Morris圖表 - 如何格式懸停標籤

graph picture

$(function() { 
       "use strict"; 

       var monthNames = [ "Oca", "Şub", "Mar", "Nis", "May", "Haz","Tem", "Ağu", "Eyl", "Eki", "Kas", "Ara" ]; 


       // LINE CHART 
       var line = new Morris.Line({ 
        element: 'kelime-gecmisi', 
        resize: true, 

        data: [ 
         {tarih: '2014-07-05', sira: 30}, 
         {tarih: '2014-07-06', sira: 25}, 
         {tarih: '2014-07-07', sira: 19}, 
         {tarih: '2014-07-08', sira: 17}, 
         {tarih: '2014-07-09', sira: 11}, 
         {tarih: '2014-07-10', sira: 8}, 
         {tarih: '2014-07-11', sira: 4}, 
         {tarih: '2014-07-12', sira: 1}, 
//      {tarih: '2014-07-13', item1: 1/3}, 
//      {tarih: '2014-07-14', item1: 1/4}, 
//      {tarih: '2014-07-15', item1: 1/9} 
        ], 
        xkey: 'tarih', 
        ykeys: ['sira'], 
        xLabels:'day', 
        // continuousLine:false, 
        labels: ['Sıra'], 
        lineWidth: 2, 
        lineColors: ['#00A65A'], 
        hideHover: 'auto', 
        ymin:'auto 1', 
        ymax:'auto 30', 
        gridIntegers: true, 




        xLabelFormat: function(d) { 
        return d.getDate()+' '+monthNames[d.getMonth()]+' '+d.getFullYear(); 
        }, 

        //yLabelFormat: function(y) { if (y === 0) return 30; else return Math.round(1/y); } 


       }); 
      }); 

回答

0

http://jsbin.com/ziyupujewe/1/edit?html,js,output

{ y: ..., x: ..., label: "my own label"},' 

... 
Morris.Line({ 
    hoverCallback: function(index, options, content) { 
     var data = options.data[index]; 
     $(".morris-hover").html('<div>Custom label: ' + data.label + '</div>'); 
    }, 
    ... 
    other params 
}); 
0
dateFormat: function (d) { 

      var ds = new Date(d); 
      return ds.getHours() + ":" + ds.getMinutes(); 
     } 

它的日期格式,被旋轉了豚鼠輪幾個小時,直到我注意到,日期格式有一個錯字作爲DAT 一個格式(這對綠色日食)

爲紅色,被自動格式化我,你也可以偷看源代碼!

0

您可以使用dateformat選項:

"dateFormat": function(unixTime) { 
    var d = new Date(unixTime); 
    var monthNames = [ 
     "Oca", "Şub", "Mar", "Nis", "May", "Haz", 
     "Tem", "Ağu", "Eyl", "Eki", "Kas", "Ara" 
    ]; 
    return d.getDate() + ' ' + monthNames[d.getMonth()] + ' ' + d.getFullYear(); 
}