2015-04-07 111 views
0

我在試圖在我的谷歌圖表中設置垂直軸縮放。我對自動縮放並不滿意,因爲我得到了兩個結果,並且想要在蘋果與蘋果的比較中看到它們的平衡。在谷歌圖表api中設置垂直軸縮放

這是我的代碼。我已經設置了最大值和最小值,但似乎並不適用於輸出。

代碼

function createExpenseChart(data) { 
     google.load("visualization", "1", {packages:["corechart"]}); 

     var chartdata = new google.visualization.DataTable(); 

    chartdata.addColumn('number', 'Expense'); 
    chartdata.addColumn('number', '2013'); 
     chartdata.addColumn('number', '2014'); 

     for (var k in data["Expense"]["2013"]){ 
      if (data["Expense"]["2013"].hasOwnProperty(k)) { 
["2013"][k],10),parseInt(data["Expense"]["2014"][k],10)]) 
       chartdata.addRow([parseInt(k,10),parseInt(data["Expense"]["2013"][k],10),parseInt(data["Expense"]["2014"][k],10)]); 
      } 
     } 

    var options = {'title':'2013 vs. 2014 comparison, 
       curveType: 'function', 

viewWindowMode:'explicit', 
       viewWindow:{ 
       max:100000, 
       min:10000 
     }, 
     vAxis: {title: 'Cost ($)', 
         minValue: 0, 
       }, 
     hAxis: {title: 'Expense (dollars)'}, 
     height: 600, 
     width: 1000 
    }; 

    var chart = new google.visualization.LineChart(document.getElementById('mydiv')); 
    chart.draw(chartdata, options); 
} 

我也曾嘗試以下,但他們並沒有表現出任何效果

var options = {'title':'2013 v/s 2014', 
       curveType: 'function', 

viewWindowMode:'explicit', 
       viewWindow:{ 
       max:80, 
       min:20 
     }, 
vAxis: { 
title: 'Cost ($)' 
    viewWindowMode:'explicit', 
    viewWindow: { 
     max:10000, 
     min:10000 
    } 
}, 
     hAxis: {title: 'Expense (dollars)'}, 
     height: 600, 
     width: 1000 
    }; 

回答

0

對不起球員,這是解決。幾乎相同的代碼工作了我。我只需要清理緩存。

對不起,我感到困惑。

function createExpenseChart(data) { 
     google.load("visualization", "1", {packExpenses:["corechart"]}); 

     var chartdata = new google.visualization.DataTable(); 

    chartdata.addColumn('number', 'Expense'); 
    chartdata.addColumn('number', 'Previous Cost'); 
     chartdata.addColumn('number', '2014 Cost'); 

     for (var k in data["Expense"]["2013"]){ 
      if (data["Expense"]["2013"].hasOwnProperty(k)) { 
       //console.log([parseInt(k,10),parseInt(data["Expense"]["2013"][k],10),parseInt(data["Expense"]["2014"][k],10)]) 
       chartdata.addRow([parseInt(k,10),parseInt(data["Expense"]["2013"][k],10),parseInt(data["Expense"]["2014"][k],10)]); 
      } 
     } 

    var formatter = new google.visualization.NumberFormat({negativeColor: 'red', negativeParens: true, pattern: '$###,###'}); 
    formatter.format(chartdata, 1); 
    formatter.format(chartdata, 2); 

    var options = {'title':'2013 vs. 2014 Costs by Expense', 
       curveType: 'function', 
       viewWindowMode:'explicit', 
       viewWindow:{ 
         min:0 
     }, 
     vAxis: {title: 'Cost ($)', 
       viewWindowMode : 'explicit', 
       viewWindow: 
       { 
         min: 0, 
         max:42000000 
       } 
       }, 
     hAxis: {title: 'Expense (years)'}, 
     height: 600, 
     width: 1000 
    }; 

    var chart = new google.visualization.LineChart(document.getElementById('Expensecostdiv')); 
    chart.draw(chartdata, options); 
} 
+0

請問你能解釋一下'你差不多'的意思嗎? – Androbin

+0

@Androbin,以及完全相同的工作,我只需要清理我的緩存。 – user121

+0

所以,如果這個問題沒有意義,那麼你可以刪除它嗎? – Androbin