2012-10-08 15 views
12

Google Charts TableにCSSスタイルを追加しようとしています。最初のセル(マイク)にGoogle Chartsのスタイル設定表

https://developers.google.com/chart/interactive/docs/gallery/table#customproperties

が、それはうまくいきませんでした:私はこれを試してみました。 options変数でallowHtmlをtrueに設定しました。個々の細胞の背景、テキストの色などを変更するにはどうすればよいですか?ありがとうございました。

<script type="text/javascript"> 
     google.load('visualization', '1', {packages:['table']}); 
     google.setOnLoadCallback(drawTable); 
     function drawTable() { 
      var data = new google.visualization.DataTable(); 
      data.addColumn('string', 'Employee Name'); 
      data.addColumn('date', 'Start Date'); 
      data.addRows(3); 
      data.setCell(0, 0, 'Mike', {style: 'background-color:red;'}); 
      data.setCell(0, 1, new Date(2008, 1, 28)); 
      data.setCell(1, 0, 'Bob'); 
      data.setCell(1, 1, new Date(2007, 5, 1)); 
      data.setCell(2, 0, 'Alice'); 
      data.setCell(2, 1, new Date(2006, 7, 16)); 

      var options = { 
       allowHtml: true 
      }; 

      // Create a formatter. 
      // This example uses object literal notation to define the options. 
      var formatter = new google.visualization.DateFormat({formatType: 'long'}); 

      // Reformat our data. 
      formatter.format(data, 1); 

      // Draw our data 
      var table = new google.visualization.Table(document.getElementById('dateformat_div')); 
      table.draw(data, options); 
     } 
    </script> 
+0

Googleのグラフの表はSVGではないため、HTMLであるため、新しいCSSスタイルを追加するだけでスタイルを変更できるはずです。 – user1477388

+8

これは読んでいますか? https://developers.google.com/chart/interactive/docs/examples#custom_table_example –

+0

ボンダイありがとうございました! – carlosgg

答えて

11

はどのようにして、個々のセルの背景、テキストの色などを変更できますか?ありがとうございました。

Per @ Bondyeのコメントには、回答は開発者ガイドに記載されています。

https://developers.google.com/chart/interactive/docs/examples#custom_table_example

あなたの条件に一致するスタイル規則を定義します。描かれたとき

<style> 
.orange-background { 
    background-color: orange; 
    } 

.orchid-background { 
    background-color: orchid; 
} 

.beige-background { 
background-color: beige; 
    } 
</style> 

はテーブルにそれらを適用します。

+2

リンク(特に外部リソース)のみで構成されるアンサーは、[so]の良い答えとはみなされません。リンク腐敗の可能性は、そのURLが死ぬ(または変更される)場合、あなたの投稿に有用な情報が含まれないことを意味します。 – Lix

+0

あなたの投稿**に関連するソリューションを**ここに追加してください。 – Lix

+1

@Lix - 要求通りに更新されました。いいですよ。投票を削除してください。ありがとう。 –

関連する問題