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

class anychart.core.Chart Improve this Doc

Extends: anychart.core.VisualBaseWithBounds

Base class for all charts, contains the margins, the background and the title.

Methods Overview

Miscellaneous
animation()Getter for the current animation setting.
background()Getter for the current chart background.
draw()Starts the rendering of the chart into the container.
label()Getter for chart label.
margin()Getter for the current chart margin.
padding()Getter for the current chart padding.
title()Getter for chart title.
toJson()Return chart configuration as JSON object or string.
toXml()Return chart configuration as XML string or XMLNode.

Methods Description

animation

Getter for the current animation setting.

Returns:

anychart.core.utils.Animation - Returns true if the animation is enabled.
Setter for the animation setting by one value.

Params:

NameTypeDefaultDescription
valueboolean | Object
false
Whether to enable animation.

Returns:

anychart.core.Chart - Self instance for method chaining.
Setter for the animation setting.

Params:

NameTypeDescription
enabledbooleanWhether to enable animation.
durationnumberDuration in milliseconds.

Returns:

anychart.core.Chart - Self instance for method chaining.

background

Getter for the current chart background.

Returns:

anychart.core.ui.Background - The current chart background.
Setter for the chart background.

Params:

NameTypeDescription
valueObjectBackground object to set.

Returns:

anychart.core.Chart - Self instance for method chaining.

draw

Starts the rendering of the chart into the container.

Returns:

anychart.core.Chart - Self instance for method chaining.

label

Getter for chart label.

Params:

NameTypeDefaultDescription
indexstring | number
0
Index of instance.

Returns:

anychart.core.ui.Label - An instance of class for method chaining.
Setter for chart label.

Params:

NameTypeDescription
valuenull | boolean | Object | stringChart label instance to add by index 0.

Returns:

anychart.core.Chart - Self instance for method chaining.
Setter for chart label.

Params:

NameTypeDescription
indexstring | numberIndex of instance.
valuenull | boolean | Object | stringChart label instance.

Returns:

anychart.core.Chart - Self instance for method chaining.

margin

Getter for the current chart margin.

Returns:

anychart.core.utils.Margin - The current chart margin.
Setter for the chart margin in pixels using a single complex object.

Params:

NameTypeDescription
valueArray.<(number|string)> | ObjectValue to set.

Returns:

anychart.core.Chart - Self instance for method chaining.
Example.
// all margins 15px
chart.margin(15);
// all margins 15px
chart.margin("15px");
// top and bottom 5px ,right and left 15px
chart.margin(anychart.utils.space(5, 15));
Setter for the chart margin in pixels using several simple values.

Params:

NameTypeDescription
value1string | numberTop or top-bottom space.
value2string | numberRight or right-left space.
value3string | numberBottom space.
value4string | numberLeft space.

Returns:

anychart.core.Chart - Self instance for method chaining.
Example.
// 1) all 10px
chart.margin(10);
// 2) top and bottom 10px, left and right 15px
chart.margin(10, "15px");
// 3) top 10px, left and right 15px, bottom 5px
chart.margin(10, "15px", 5);
// 4) top 10px, right 15px, bottom 5px, left 12px
chart.margin(10, "15px", "5px", 12);

padding

Getter for the current chart padding.

Returns:

anychart.core.utils.Padding - Current chart padding.
Setter for the chart paddings in pixels using a single value.

Params:

NameTypeDescription
valueArray.<(number|string)> | ObjectValue to set.

Returns:

anychart.core.Chart - Self instance for method chaining.
Example.
chart.padding([5, 15]);
Example.
chart.padding({left: 10, top: 20, bottom: 30, right: "40%"}});
Setter for the chart paddings in pixels using several numbers.

Params:

NameTypeDescription
value1string | numberTop or top-bottom space.
value2string | numberRight or right-left space.
value3string | numberBottom space.
value4string | numberLeft space.

Returns:

anychart.core.Chart - Self instance for method chaining.
Example.
// 1) all 10px
chart.padding(10);
// 2) top and bottom 10px, left and right 15px
chart.padding(10, "15px");
// 3) top 10px, left and right 15px, bottom 5px
chart.padding(10, "15px", 5);
// 4) top 10px, right 15%, bottom 5px, left 12px
chart.padding(10, "15%", "5px", 12);

title

Getter for chart title.

Returns:

anychart.core.ui.Title - The current chart title.
Setter for the chart title.

Params:

NameTypeDescription
valuenull | boolean | Object | stringChart title text or title instance for copy settings from.

Returns:

anychart.core.Chart - Self instance for method chaining.

toJson

Return chart configuration as JSON object or string. Note for documentation writers!: Google compiler thinks that "Object" has "toJSON" method that must accept string and return *. To avoid this we have to put in the "wrong" params. In external documentation parameter must be boolean, and method must return Object|string. For the moment we have no way around this "nice feature" of the compiler.

Params:

NameTypeDescription
stringifystringReturn as JSON as string.

Returns:

* - Chart JSON.

toXml

Return chart configuration as XML string or XMLNode.

Params:

NameTypeDescription
asXmlNodebooleanReturn XML as XMLNode.

Returns:

string | Node - Chart configuration.