2014-12-19 120 views
0

我碰到一個有趣的問題,我無法用型「日期時間」和的X軸加點與動態添加類動態添加數據系列Y軸的動態類型和動態添加一系列的HighChart:在Y軸

$(document).ready(function() { 
     drawScatter(); 
     $('#addSeries').on('click', function() { 
      //first check if value is already a series 
      var currentDate = new Date(); 
      var id = document.getElementById('txtValue').value; 
      getSeriesIndexByEventID(eventid, function(index) { 
       //if it doesnt exist, add it to chart 
       if (index == -1) { 
        categories.push(id + ' category'); 
        console.log(categories); 
        chart.yAxis[0].setCategories(categories); 
        idSeries.push({name: id+ 'n', data: [categories.length-1, [{x: currentDate.getTime()}]]}); 
        chart.addSeries(idSeries[idSeries.length-1]); 
        console.log(chart.series[categories.length-1]); 
       } 
      }); 
     }); 
    }): 

這裏是一個的jsfiddle http://jsfiddle.net/5L59r1qt/10/

我希望能夠點擊該按鈕,並與裏面的文字將其添加爲一個系列。它這樣做,但它不會做正確的時間!

回答

0

您在addSeries中有不正確的數據數組。它應該是x/y值的對象。

idSeries.push({name: id+ 'n', data: [{x: currentDate.getTime(),y:categories.length-1}]}); 

http://jsfiddle.net/5L59r1qt/12/