Top
You are looking at an outdated 7.12.0 version of this document. Switch to the 8.0.1 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:

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.

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.

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 current items formatter.

Returns:

function - The current formatter function.
See listing
var currentContextMenu = chart.contextMenu();
var currentFormatter = currentContextMenu.itemsFormatter();
Setter for the items formatter.

Params:

Name Type Default Description
value function
function(this:Array anychart.ui.ContextMenu.Item, Array anychart.ui.ContextMenu.Item,
anychart.ui.ContextMenu.PrepareItemsContext)
return Array anychart.ui.ContextMenu.Item
Formatter function.

Returns:

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

Try it:

itemsProvider

Getter for the current items provider.
Note: Items provider called before items formatter.

Returns:

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

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.
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.
listenerScope Object
Object in whose scope to call the listener.

Returns:

boolean - Whether any listener was removed.

Try it: