當創建按鈕,構造函數有更多的參數,從源代碼:
/**
* Create a button with preset states
* @param {String} text
* @param {Number} x
* @param {Number} y
* @param {Function} callback
* @param {Object} normalState
* @param {Object} hoverState
* @param {Object} pressedState
*/
button: function (text, x, y, callback, normalState, hoverState, pressedState, disabledState, shape) {
...
),
因此,您不應使用attr()
或css()
作爲樣式,但使用預定義的選項。例如:
var normalState = {
fill: '#000000',
style: {
color: '#FFFFFF'
}
},
hoverState = {
fill: '#000000',
style: {
color: '#FFFFFF'
}
},
pressedState = {
fill: '#000000',
style: {
color: '#FFFFFF'
}
},
disabledState = {
fill: '#000000',
style: {
color: '#FFFFFF'
}
},
callback = function() {
console.log('clicked!');
}
var testbutton = chart.renderer.button('button1', 0, 10, callback, normalState, hoverState, pressedState, disabledState).attr({ ... }).css({ ... }).add()
當然,所有選項都可以是相同的:
var styles = {
fill: '#000000',
style: {
color: '#FFFFFF'
}
},
callback = function() {
console.log('clicked!');
}
var testbutton = chart.renderer.button('button1', 0, 10, callback, styles, styles, styles, styles).att({ ... }).css({ ... }).add();
最後一個現場演示:http://jsfiddle.net/NxK39/82/
感謝您的回答..我已經嘗試了小提琴和它適合我的工作.. – user3357897