class anychart.ui.ContextMenu Improve this Doc
The ContextMenu class contains methods for configuring context menu.
Methods Overview
Specific settings | |
attach() | Attaches the context menu to a chart or DOM element. |
detach() | Detaches the context menu from a given element or chart. |
items() | Context menu items |
itemsFormatter() | Function to format items. |
itemsProvider() | Function to items provider. |
serialize() | Serializes element to JSON. |
setup() | Setups the element using passed configuration value. |
Events | |
listen() | Adds an event listener for an event to a context menu. |
unlisten() | Removes a listener added using listen() or listenOnce() methods. |
Interactivity | |
enabled() | Context menu state (enabled or disabled). |
hide() | Hides the context menu. |
show() | Shows the menu immediately at the given client coordinates. |
Miscellaneous | |
addClassName() | Setter for the class name. |
removeClassName() | Removes the class name. |
Methods Description
addClassName
Setter for the class name.
Detailed description
Adds the given class name to the list of classes to be applied to the context menu's root element.
Params:
Name | Type | Description |
---|---|---|
className | string | Additional class name to be applied to the context menu of the root element. |
Try it:
attach
Attaches the context menu to a chart or DOM element.
Detailed description
A menu can be only attached to a target once, since attaching the same menu for
multiple targets. This method will render the context menu in the document.body.
Params:
Name | Type | Description |
---|---|---|
target | Element | anychart.core.Chart | Target for showing of context menu by right click. |
capture | boolean | Whether to use capture phase. Learn more about capturing https://javascript.info/bubbling-and-capturing |
Returns:
anychart.ui.ContextMenu - Self instance for method chaining.Try it:
detach
Detaches the context menu from a given element or chart.
Params:
Name | Type | Description |
---|---|---|
target | Element | Element for showing of context menu by right click. |
capture | boolean | Whether to use capture phase. Learn more about capturing https://javascript.info/bubbling-and-capturing |
Returns:
anychart.ui.ContextMenu - Self instance for method chaining.Try it:
enabled
Getter for the context menu state (enabled or disabled).
Returns:
boolean | null - The context menu state.Try it:
Setter for the context menu enabled state.
Params:
Name | Type | Default | Description |
---|---|---|---|
enabled | boolean | true | Whether context menu enabled. |
Returns:
anychart.ui.ContextMenu - Self instance for method chaining.Try it:
hide
Hides the context menu.
Try it:
items
Getter for the context menu items.
Returns:
Array.<anychart.ui.ContextMenu.Item> - Returns an array of the items by sharing.Try it:
Setter for the context menu items.
Detailed description
This method is only necessary to use anychart.ui.ContextMenu#show method.
The anychart.ui.ContextMenu#items and anychart.ui.ContextMenu#itemsProvider methods are mutually exclusive so setting both does not make sense.
The anychart.ui.ContextMenu#items and anychart.ui.ContextMenu#itemsProvider methods are mutually exclusive so setting both does not make sense.
Params:
Name | Type | Description |
---|---|---|
itemsList | Array.<anychart.ui.ContextMenu.Item> | Items list to set. |
Returns:
anychart.ui.ContextMenu - Self instance for method chaining.Try it:
itemsFormatter
Getter for the items formatter.
Returns:
function - Formatter function. See listing
var contextMenu = chart.contextMenu(); var formatter = contextMenu.itemsFormatter();
Setter for the items formatter.
Params:
Name | Type | Description |
---|---|---|
formatter | function(item1:Object, item2:Object, context:anychart.ui.ContextMenu.PrepareItemsContext):Object | Formatter function. |
Returns:
anychart.ui.ContextMenu - Self instance for method chaining.Try it:
itemsProvider
Getter for the items provider.
Note: Items provider called before items formatter.
Note: Items provider called before items formatter.
Returns:
function - Items formatter function. See listing
var contextMenu = chart.contextMenu(); var itemsProvider = contextMenu.itemsProvider();
Setter for the items provider.
Detailed description
Items provider called before items formatter.
The anychart.ui.ContextMenu#items and anychart.ui.ContextMenu#itemsProvider methods are mutually exclusive so setting both does not make sense.
The anychart.ui.ContextMenu#items and anychart.ui.ContextMenu#itemsProvider methods are mutually exclusive so setting both does not make sense.
Params:
Name | Type | Description |
---|---|---|
function | function(itemsContext1:anychart.ui.ContextMenu.PrepareItemsContext, itemsContext2:anychart.ui.ContextMenu.PrepareItemsContext):Object | Formatter function. |
Returns:
anychart.ui.ContextMenu - Self instance for method chaining.Try it:
listen
Adds an event listener for an event to a context menu.
Detailed description
The listener can be added to an object once, and if it is one more time, its key will be returned.
Notice that if the existing listener is a one-off (added using listenOnce),
it will cease to be such after calling the listen() method.
Params:
Name | Type | Default | Description |
---|---|---|---|
type | string | The event type id. | |
listener | function(e:Object):boolean|undefined | Callback method. | |
useCapture | boolean | false | Whether to fire in capture phase. Learn more about capturing https://javascript.info/bubbling-and-capturing |
listenerScope | Object | Object in whose scope to call the listener. |
Returns:
Object - Unique key for the listener.Try it:
removeClassName
Removes the class name.
Detailed description
Removes the given class name from the list of classes to be applied to the context menu of the root element.
Params:
Name | Type | Description |
---|---|---|
className | string | Class name which to be removed from the context menus root element. |
Try it:
serialize
setup
Setups the element using passed configuration value.
Detailed description
It can be a JSON object or a special value that setups instances of descendant classes.
Note: this method only changes element properties if they are supposed to be changed by the config value -
it doesn't reset other properties to their defaults.
Params:
Name | Type | Description |
---|---|---|
var_args | Object | Array | number | string | undefined | boolean | null | Arguments to setup the instance. |
Returns:
anychart.ui.ContextMenu - Self instance for method chaining.Try it:
show
Shows the menu immediately at the given client coordinates.
Detailed description
You have to specify a set of menu items using anychart.ui.ContextMenu#items method before calling.
Params:
Name | Type | Description |
---|---|---|
x | number | The client-X associated with the show event. |
y | number | The client-Y associated with the show event. |
Try it:
unlisten
Removes a listener added using listen() or listenOnce() methods.
Params:
Name | Type | Default | Description |
---|---|---|---|
type | string | The event type id. | |
listener | function(e:Object):boolean|undefined | Callback method. | |
useCapture | boolean | false | Whether to fire in capture phase. Learn more about capturing https://javascript.info/bubbling-and-capturing |
listenerScope | Object | Object in whose scope to call the listener. |
Returns:
boolean - Whether any listener was removed.Try it: