问题
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