2013-10-24 44 views
0

如何使用谷歌图表(google.visualization API)在折线图上设置特定线条的颜色?我正在可视化一个已经具有与每一行相关的特定颜色的数据集(并且颜色关联很重要)。如何为特定线路分配特定颜色? (google.visualization)

我知道通过图表选项设置一般的调色板,例如:

chart.draw(dataTable, { colors: ['red', '#ff9933', 'pink', /* ...etc... */ ] }); 

但我不希望设置一个调色板,我要指派特定颜色的具体线路。理想情况下,我想将颜色放入数据表本身。

回答

0

你不能把颜色DataTable中,但可以通过数据系列,为它们分配使用一系列选项:

chart.draw(dataTable, { 
    series: { 
     0: { 
      // set the color of the first data series 
      color: 'red' 
     }, 
     1: { 
      // set the color of the second data series 
      color: '#ff9933' 
     }, 
     2: { 
      // set the color of the third data series 
      color: 'pink' 
     } 
     // etc 
    } 
}); 

如果你的数据系列是动态的,可以动态生成颜色好吧,并在抽签时将它们设置在选项中。