只要谷歌不会在将来改变API,这种黑客行为。此外,它的作品,直到你不使用实验选项“探险家”。如果您使用缩放,则图表会在每个鼠标滚轮事件中重新呈现,并且您的值已消失。非常可悲的是,图表API不会暴露任何缩放或重新渲染事件。在绘制图表后,只有一次“准备好”事件被触发。此外,我注意到,我不能计算出我提供给api的yAxis值。如果api决定这些字符串太长,它只会用工具提示渲染它的子字符串。
所以,只有一个笨拙和一个真正的解决方法,我能够想出。我离开了笨拙的一个,因为它符合以前的帖子
var chartDiv = document.getElementById ("chart");
chartDiv .addEventListener ("mousewheel", ProcessChart, false);
//take care of "mousewheel" event browser compatibility!!!
function ProcessChart() {
setTimeout(function() {
$("#chart svg text[text-anchor='end']:contains('$C$')").each(function() {
var $this = $(this);
var val = parseInt($this.text());
var label = GetCommunicationLabel(val);
$this.text(label);
});
}, 20);
}
请注意,我用setTimeout函数来处理标签。该图表也是在mousewheel事件上呈现的,如果没有延迟,您将尝试处理尚不存在的标签。20毫秒只是实验值,它取决于您的图表在鼠标滚轮事件上重新渲染的时间。不幸的是,当旧值被替换时,用户能够检测到闪烁。
我终于找到了真正的解决方案。
vAxes: {
0: {
format: '#%',
ticks: [0, 0.25, 0.5, 0.75, 1]
//minValue: 0,
//maxValue: 1,
//title: batteryText,
},
1: {
ticks: [ { v: 0, f: GetCommunicationLabel(0) },
{ v: 1, f: GetCommunicationLabel(1) },
{ v: 2, f: GetCommunicationLabel(2) },
{ v: 3, f: GetCommunicationLabel(3) },
{ v: 4, f: GetCommunicationLabel(4) }],
// format: "#",
textPosition: 'out'
//minValue: 0,
//maxValue: 3,
//title: communicationText,
}
},