AnyChart
API Reference
Still have questions?
Contact support
Top
You are looking at an outdated v7 version of this document. Switch to the v8 version to see the up to date information.

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:

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

Returns:

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

Params:

NameTypeDefaultDescription
valueboolean
true
Value to set.

Returns:

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

hide

Hides the context menu.

items

Getter for the current context menu items.

Returns:

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

Params:

NameTypeDescription
valueArray.<anychart.ui.ContextMenu.Item>Items.

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.
Learn more about using itemsFormat() method.

Params:

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

Params:

NameTypeDefaultDescription
valuefunction
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.

listen

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

Params:

NameTypeDefaultDescription
typestring
The event type id.
listenerfunction
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
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.