Charts 谷歌图表中堆叠(正/负)条形图中的第二个Y轴
我构建了一个堆叠条形图来说明正负值,如下所示: 因为这些值表示相反方向,所以我想向右Y轴添加其他标签。这可能吗?到目前为止,我的代码是:Charts 谷歌图表中堆叠(正/负)条形图中的第二个Y轴,charts,google-visualization,Charts,Google Visualization,我构建了一个堆叠条形图来说明正负值,如下所示: 因为这些值表示相反方向,所以我想向右Y轴添加其他标签。这可能吗?到目前为止,我的代码是: var data = google.visualization.arrayToDataTable([ ['Type', 'Value1', 'Value2'], ['Left-1', 0, -5], ['Left-2', 0, -3], ['Left-3', 0, 0],
var data = google.visualization.arrayToDataTable([
['Type', 'Value1', 'Value2'],
['Left-1', 0, -5],
['Left-2', 0, -3],
['Left-3', 0, 0],
['Left-4', 3, 0],
['Left-5', 5, 0]
]);
var options = {
legend: 'none',
hAxis: {
minValue: -6,
maxValue: 6
}
}
var chart = new google.visualization.BarChart(document.getElementById('chart_div'));
chart.draw(data, options);
jsiddle:此配置中没有任何用于附加轴的标准选项 但您可以添加自定义标签 一旦触发
'ready'
事件
请参阅以下工作片段
google.charts.load('current'{
回调:图纸,
软件包:['corechart']
});
函数绘图图(){
var data=google.visualization.arrayToDataTable([
['Type','Value1','Value2'],
[Left-1',0,-5],
[Left-2',0,-3],
['Left-3',0,0],
[Left-4',3,0],
['Left-5',5,0]
]);
变量选项={
图例:“无”,
哈克斯:{
最小值:-6,
最大值:6
}
}
var chartDiv=document.getElementById('chart_div');
var chart=新的google.visualization.BarChart(chartDiv);
google.visualization.events.addListener(图表'ready',函数(){
Array.prototype.forEach.call(chartDiv.getElementsByTagName('text'),函数(axisLabel){
if(axisLabel.getAttribute('text-anchor')=='end'){
添加标签(
axisLabel,
chart.getChartLayoutInterface().getChartAreaBoundingBox().left+
chart.getChartLayoutInterface().getChartAreaBoundingBox().width-24//awesome!非常感谢,在web上找不到任何内容。我添加了一个axisLabel.setAttribute('text-anchor','start')
,以使标签左对齐。右侧看起来更好,但在本例中不可见。