Annotation color only shows when text outside of Google Bar Chart

白昼怎懂夜的黑 提交于 2021-01-29 00:51:01

问题


I have a google bar chart and I am setting the font size and the color, however the color only applies when the text is outside of the bar. How do I force the color to apply?

 annotations: {
        textStyle: {
          fontSize: 18,
          color:'#000000'
        }
      }


回答1:


turn off annotations.highContrast

from the documentation...

annotations.highContrast lets you override Google Charts choice of the annotation color.
By default, annotations.highContrast is true, which causes Charts to select an annotation color with good contrast: light colors on dark backgrounds, and dark on light.
If you set annotations.highContrast to false and don't specify your own annotation color, Google Charts will use the default series color for the annotation:

see following example, note the use of textStyle.auraColor

google.charts.load('current', {
  callback: function () {
    new google.visualization.ColumnChart(document.getElementById('chart_div')).draw(
      google.visualization.arrayToDataTable([
        ['Element', 'Density', { role: 'annotation' } ],
        ['Copper', 8.94, 'Cu' ],
        ['Silver', 10.49, 'Ag' ],
        ['Gold', 19.30, 'Au' ],
        ['Platinum', 21.45, 'Pt' ]
      ]),
      {
        annotations: {
          highContrast: false,
          textStyle: {
            auraColor: 'lime',
            color: '#000000',
            fontSize: 18
          }
        },
        colors: ['lime']
      }
    );
  },
  packages: ['corechart']
});
<script src="https://www.gstatic.com/charts/loader.js"></script>
<div id="chart_div"></div>

another option might be annotations.alwaysOutside



来源:https://stackoverflow.com/questions/37126144/annotation-color-only-shows-when-text-outside-of-google-bar-chart

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!