2012-07-12 74 views
0

我的應用程序中的顏色沒有改變。我必須製作柱形圖,但x軸上的每個標籤上的顏色都沒有變化。柱形圖中顏色不變

<html> 
    <head> 
    <script type="text/javascript" src="https://www.google.com/jsapi"></script> 
    <script type="text/javascript"> 
     google.load("visualization", "1", {packages:["corechart"]}); 
     google.setOnLoadCallback(drawChart); 
     function drawChart() { 
     var data = google.visualization.arrayToDataTable([ 
      ['Year', 'Sales'], 
      ['2004', 1000], 
      ['2005', 1170], 
      ['2006', 660 ], 
      ['2007', 1030] 
     ]); 

     var options = { 
      colors:['#A2C180','#3D7930','#FFC6A5','#FFFF42','#DEF3BD','#00A5C6','#DEBDDE','#000000'], 
      title: 'Company Performance', 
      hAxis: {title: 'Year', titleTextStyle: {color: 'red'}} 
     }; 

     var chart = new google.visualization.ColumnChart(document.getElementById('chart_div')); 
     chart.draw(data, options); 
     } 
    </script> 
    </head> 
    <body> 
    <div id="chart_div" style="width: 900px; height: 500px;"></div> 
    </body> 
</html> 

或任何人告訴我如何添加或顯示在給定的代碼x軸標籤....

<html> 
    <head> 
    <script type="text/javascript" src="https://www.google.com/jsapi"></script> 
    <script type="text/javascript"> 
     google.load("visualization", "1", {packages:["corechart"]}); 
     google.setOnLoadCallback(drawChart); 
     function drawChart() { 
     var data = new google.visualization.DataTable(); 
    var raw_data = [ 
    ["January", parseFloat('120')], 
    ["Februry", parseFloat('150')], 
    ["March", parseFloat('50')], 
    ["April", parseFloat('90')], 
    ["May", parseFloat('100')], 
    ["June", parseFloat('130')] 
    ]; 
    var years = [' ']; 

    data.addColumn('string', 'sales'); 
    for (var i = 0; i < raw_data.length; ++i) { 
     data.addColumn('number', raw_data[i][0]); 
    } 

    data.addRows(years.length); 

    for (var j = 0; j < years.length; ++j) { 
     data.setValue(j, 0, years[j].toString()); 
    } 
    for (var i = 0; i < raw_data.length; ++i) { 
     for (var j = 1; j < raw_data[i].length; ++j) { 
      data.setValue(j-1, i+1, raw_data[i][j]); 
     } 
    } 
     var options = { 
      colors:['#A2C180','#3D7930','#FFC6A5','#FFFF42','#DEF3BD','#00A5C6','#DEBDDE','#000000'], 
      title: 'Company Performance', 
      hAxis: {title: 'Year', titleTextStyle: {color: 'red'}} 
     }; 

     var chart = new google.visualization.ColumnChart(document.getElementById('chart_div')); 
     chart.draw(data, options); 
     } 
    </script> 
    </head> 
    <body> 
    <div id="chart_div" style="width: 900px; height: 500px;"></div> 
    </body> 
</html> 

回答

1

隨着谷歌的圖表,它認爲該數據必須是隻有一個系列具有4個值的數據,而不是用於單獨的數據位,並且將顏色應用於該系列中的每個條實際上是不可能的。

有幾種方法幾乎可以達到你想要的效果,如question/answer所示,但不幸的是,沒有什麼能夠完全給你所期望的。

+0

okies ....你能告訴我如何在給定的代碼上添加x軸標籤..... – 2012-07-12 13:17:57

+1

將關於標籤的問題發佈爲新問題。 – JJJ 2012-07-12 14:02:47