【问题标题】:Different Color to Label标签的不同颜色
【发布时间】:2014-03-14 08:10:30
【问题描述】:

如何在下面链接的第一个图中为 Google Visualization 的 x 轴标签(如 2004、2005、2006、2007)赋予不同的颜色?

https://developers.google.com/chart/interactive/docs/gallery/linechart.

我用过这段代码。

google.load("visualization", "1", {packages:["corechart"]});
  google.setOnLoadCallback(drawChart);
  function drawChart() {
    var data = google.visualization.arrayToDataTable([
      ['Year', 'Sales', 'Expenses'],
      ['2004',  1000,      400],
      ['2005',  1170,      460],
      ['2006',  660,       1120],
      ['2007',  1030,      540]
    ]);

    var options = {
      title: 'Company Performance'
    };

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

【问题讨论】:

  • 您无法更改单个标签的颜色,抱歉。

标签: javascript jquery google-visualization


【解决方案1】:
options = [{ 
   //you can set the baseline color of the axis and the text like :
   hAxis: {
       baselineColor: '#c9311b',
       textStyle:{color: 'red'}
   },
   vAxis: {
       baselineColor: '#cccccc',
       textStyle:{color: 'yellow'}
   },
   // and the series (labels) like : 
   series=[{targetAxisIndex:0, 
       color:'red'}, 
       {targetAxisIndex:1,
       color:'blue'
    }]
}]

维度的targetAxisIndex在哪里

【讨论】:

  • 它正在改变图例的颜色,例如(销售和费用)而不是 haxis 标签的颜色(2005、2006 等)。
  • 我想在 xaxis 标签上使用不同的颜色。它给出了相同的颜色。放置此 textStyle:{color: 'red'} 的示例将所有 hAxis 标签转换为红色。
猜你喜欢
  • 1970-01-01
  • 2019-08-25
  • 2015-04-14
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2020-09-09
相关资源
最近更新 更多