AnyChart
API Reference
Still have questions?
Contact support
Top

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.

Params:

NameTypeDescription
classNamestringAdditional class name to be applied to the context menu of the root element.

attach

Attaches the context menu to a chart or DOM element.

Params:

NameTypeDescription
targetElement | anychart.core.ChartTarget for showing of context menu by right click.
capturebooleanWhether to use capture phase. Learn more about capturing https://javascript.info/bubbling-and-capturing

Returns:

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

detach

Detaches the context menu from a given element or chart.

Params:

NameTypeDescription
targetElementElement for showing of context menu by right click.
capturebooleanWhether to use capture phase. Learn more about capturing https://javascript.info/bubbling-and-capturing

Returns:

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

enabled

Getter for the context menu state (enabled or disabled).

Returns:

boolean | null - The context menu state.
Setter for the context menu enabled state.

Params:

NameTypeDefaultDescription
enabledboolean
true
Whether context menu enabled.

Returns:

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

hide

Hides the context menu.

items

Getter for the context menu items.

Returns:

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

Params:

NameTypeDescription
itemsListArray.<anychart.ui.ContextMenu.Item>Items list to set.

Returns:

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

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:

NameTypeDescription
formatterfunction(item1:Object, item2:Object, context:anychart.ui.ContextMenu.PrepareItemsContext):ObjectFormatter function.

Returns:

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

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 = contextMenu.itemsProvider();
Setter for the items provider.

Params:

NameTypeDescription
functionfunction(itemsContext1:anychart.ui.ContextMenu.PrepareItemsContext, itemsContext2:anychart.ui.ContextMenu.PrepareItemsContext):ObjectFormatter function.

Returns:

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

listen

Adds an event listener for an event to a context menu.

Params:

NameTypeDefaultDescription
typestring
The event type id.
listenerfunction(e:Object):boolean|undefined
Callback method.
useCaptureboolean
false
Whether to fire in capture phase. Learn more about capturing https://javascript.info/bubbling-and-capturing
listenerScopeObject
Object in whose scope to call the listener.

Returns:

Object - Unique key for the listener.

removeClassName

Removes the class name.

Params:

NameTypeDescription
classNamestringClass name which to be removed from the context menus root element.

serialize

Serializes element to JSON.

Returns:

Object - Serialized JSON object.

setup

Setups the element using passed configuration value.

Params:

NameTypeDescription
var_argsObject | Array | number | string | undefined | boolean | nullArguments to setup the instance.

Returns:

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

show

Shows the menu immediately at the given client coordinates.

Params:

NameTypeDescription
xnumberThe client-X associated with the show event.
ynumberThe client-Y associated with the show event.

unlisten

Removes a listener added using listen() or listenOnce() methods.

Params:

NameTypeDefaultDescription
typestring
The event type id.
listenerfunction(e:Object):boolean|undefined
Callback method.
useCaptureboolean
false
Whether to fire in capture phase. Learn more about capturing https://javascript.info/bubbling-and-capturing
listenerScopeObject
Object in whose scope to call the listener.

Returns:

boolean - Whether any listener was removed.