动态按钮背景更改

时间:2013-03-06 15:35:12

标签: button dynamic highcharts

我想知道这是否可能: 我添加了自己的按钮(见下文),现在我想知道是否可以在点击时动态更改按钮背景颜色。 我们的想法是模拟复选框启用/禁用。

  exporting: {
        enabled: true,
        buttons: {
            'realTimeButton': {
                id: 'realTimeButton',
                symbol: 'diamond',
                x: -62,
                symbolFill: '#B5C9DF',
                hoverSymbolFill: '#779ABF',
                _titleKey: "realTimeButtonTitle",
                onclick: function() {
                    // handle change to real time
                    if ( enable_lastRoundsChart_realtime )
                    {
                        enable_lastRoundsChart_realtime = 0;
                    }
                    else
                    {
                        enable_lastRoundsChart_realtime = 1;
                    }
                }
            }
        } 

1 个答案:

答案 0 :(得分:1)

这不可能以简单的方式进行,但您可以使用渲染器来准备自己的按钮和悬停/按下的样式。

http://jsfiddle.net/AvpDk/

normalState = new Object();
    normalState.stroke_width = null;
    normalState.stroke = null;
    normalState.fill = null;
    normalState.padding = null;
    normalState.r = null;

    hoverState = new Object();
    hoverState = normalState;
    hoverState.fill = 'red';

    pressedState = new Object();
    pressedState = normalState;

    var custombutton = chart.renderer.button('button', 74, 10, function(){
        alert('aaa');
    },null,hoverState,pressedState).add();