Top

class anychart.ui.ContextMenu Improve this Doc

Context Menu class.

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.

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.

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 current context menu state (enabled or disabled).

Returns:

boolean null - The current context menu state.

Try it:

Setter for the context menu enabled state.

Params:

Name Type Default Description
value boolean
true
Value to set.

Returns:

anychart.ui.ContextMenu - Self instance for method chaining.

Try it:

hide

Hides the context menu.

Try it:

items

Getter for the current context menu items.

Returns:

Array.<anychart.ui.ContextMenu.Item> - Returns an array of the items by sharing.

Try it:

Setter for the current context menu items.

Params:

Name Type Description
value Array.<anychart.ui.ContextMenu.Item> Items.

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
value function 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.

Returns:

function - Items formatter function.
See listing
var contextMenu = chart.contextMenu();
var itemsProvider = currentContextMenu.itemsProvider();
Setter for the items provider.

Params:

Name Type Default Description
value function
function(this:anychart.ui.ContextMenu.PrepareItemsContext,
anychart.ui.ContextMenu.PrepareItemsContext)
return Array anychart.ui.ContextMenu.Item
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.

Params:

Name Type Default Description
type string
The event type id.
listener function
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.

Params:

Name Type Description
className string Class name which to be removed from the context menus root element.

Try it:

serialize

Serializes element to JSON.

Returns:

Object - Serialized JSON object.

Try it:

setup

Setups the element using passed configuration value.

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.

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
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: