2014-02-10 64 views
1

當頁面初始加載時,我得到一組數據並將其顯示在浮動圖表中。我有一個允許用戶選擇「年迄今」或「月至日期」的下拉菜單,並且一切正常,除非圖表不重繪圖表,所以當您將選擇更改爲「月日期「,它仍然在x軸上列出所有日曆月份而不是月份的日期。我試過使用$.plot.setupGrid()$.plot.draw(),也chartTaggedSpending.setupGrid()chartTaggedSpending.draw(),它不工作,所以我在這裏做錯了什麼。預先感謝您提供的任何幫助。浮動圖表不會重新繪製

這裏有堪稱ajax.done()功能塊代碼:

if(selectView = 1 && response.length != 0) { 

     var chartTaggedSpending = $('#tagged-spending'); 
     var arrMonthLabels = [[1, 'Jan'], [2, 'Feb'], [3, 'Mar'],[4, 'Apr'], 
[5, 'May'],[6, 'Jun'], [7, 'Jul'], [8, 'Aug'], [9, 'Sep'], [10, 'Oct'], 
[11, 'Nov'], [12, 'Dec']]; 
     $.plot(chartTaggedSpending, 
      [ 
       { 
        data: response[1].data, 
        label: 'Budgeted: ' + response[1].label, 
        lines: { show: true}, 
        points: { show: true, radius: 7 } 
       }, 
       { 
        data: response[0].data, 
        label: 'Spent: ' + response[0].label, 
        lines: { show: true}, 
        points: { show: true, radius: 7 } 
       } 
      ], 
      { 
       colors: ['#a6db34', '#33a6db'], 
       legend: { show: true }, 
       grid: { borderWidth: 0, hoverable: true, clickable: true }, 
       yaxis: {min: 0, max: 2000, ticks: 10, tickColor: '#eeeeee' }, 
       xaxis: { 
        min: 1, 
        max: 12, 
        ticks: arrMonthLabels, 
        tickColor: '#ffffff' 
       } 
      } 
     ); 
    } 
    if(selectView = 0 && response.length != 0) { 
     var chartTaggedSpending = $('#tagged-spending'); 
     $.plot(chartTaggedSpending, 
      [ 
       { 
        data: response[1].data, 
        label: 'Budgeted: ' + response[1].label, 
        lines: { show: true}, 
        points: { show: true, radius: 7 }, 
       }, 
       { 
        data: response[0].data, 
        label: 'Spent: ' + response[0].label, 
        lines: { show: true}, 
        points: { show: true, radius: 7 } 
       } 
      ], 
      { 
       colors: ['#a6db34', '#33a6db'], 
       legend: { show: true }, 
       grid: { borderWidth: 0, hoverable: true, clickable: true }, 
       yaxis: {min: 0, max: 1500, ticks: 10, tickColor: '#eeeeee' }, 
       xaxis: { 
        min: 1, 
        max: 31, 
        ticks: 31, 
        tickColor: '#ffffff' 
       } 
      } 
     ); 
    } 
+0

你能告訴我你的問題的解決方案嗎?其實我也有同樣的問題。 –

回答

2

.setupGrid.draw是一個陰謀對象的方法。這個陰謀對象.plot呼叫返回

var chartTaggedSpending = $('#tagged-spending'); 
var myPlot = $.plot(chartTaggedSpending, etc.... // assign the return from $.plot 
// sometime later 
myPlot.setupGrid(); // use it later 
myPlot.draw(); 
+0

我試圖像上面演示的那樣構建上面的代碼,但我必須缺少一些東西,因爲它仍然不起作用。當我將選擇選項更改爲另一個圖表時,數據會發生變化,所以我知道一切都在進行,直到那一刻,但不管我如何嘗試,都只是不重繪圖表。 – hyphen

+0

@hyphen,你可以創建一個jsFiddle來重現你的問題嗎? – Mark