Overview
Sprite is the foundational building block for all visual elements in amCharts 5. It provides common functionality for positioning, styling, events, states, and accessibility.Creating a Sprite
Sprite is an abstract class and cannot be instantiated directly. Use specific sprite types like Rectangle, Graphics, or Container instead.Properties
Position and Dimensions
X position relative to parent
Y position relative to parent
Element’s absolute width in pixels (numeric) or relative width to parent (Percent)
Element’s absolute height in pixels (numeric) or relative height to parent (Percent)
Maximum allowed width in pixels
Maximum allowed height in pixels
Minimum allowed width in pixels
Minimum allowed height in pixels
Horizontal shift in pixels. Can be negative to shift leftward.
Vertical shift in pixels. Can be negative to shift upward.
Visual Appearance
Opacity. 0 - fully transparent; 1 - fully opaque.
Rotation in degrees
Scale. Setting to a value less than 1 will shrink object.
Is element visible?
If set to
true the element will be hidden regardless of visible or even if show() is calledPositioning
X coordinate of the center of the element relative to itself. Center coordinates will affect placement as well as rotation pivot point.
Y coordinate of the center of the element relative to itself. Center coordinates will affect placement as well as rotation pivot point.
Positioning of the element. “absolute” means element will not participate in parent layout scheme.
Margins
Left margin in pixels
Right margin in pixels
Top margin in pixels
Bottom margin in pixels
Interactivity
Should this element accept user interaction events?
If set to
true, user will be able to drag this element. It will also disable default drag events over the area of this element.If set to
true, mouse wheel events will be triggered over the element. It will also disable page scrolling using mouse wheel when pointer is over the element.If set to
true the element will be inactive - absolutely oblivious to all interactionsTooltips
Tooltip instance
Text to show in a tooltip when hovered
HTML content to show in a tooltip when hovered
Tooltip pointer X coordinate relative to the element itself
Tooltip pointer Y coordinate relative to the element itself
Tooltip position
Defines when tooltip is shown over the element
Visual Effects
An SVG filter to apply to the element. IMPORTANT: SVG filters are not supported in some browsers, e.g. Safari.
Apply blur filter. Ranges from
0 to X pixels. IMPORTANT: Not supported in Safari.Modify visual brightness. Range:
0 to 1. IMPORTANT: Not supported in Safari.Modify contrast. Range:
0 to 1. IMPORTANT: Not supported in Safari.Modify saturation.
0 = grayscale, 1 = no changes, >1 = more saturated. IMPORTANT: Not supported in Safari.Apply sepia filter. Range:
0 (no changes) to 1 (complete sepia). IMPORTANT: Not supported in Safari.Invert colors. Range:
0 (no changes) to 1 (completely inverted). IMPORTANT: Not supported in Safari.Rotate HUE colors in degrees. Range:
0 to 360. IMPORTANT: Not supported in Safari.Appearance
A named mouse cursor style to show when hovering this element
If set to
true, element will try to draw itself crisp on screen with minimal anti-aliasingLayer
Numeric layer to put element in. Elements with higher number will appear in front of ones with lower number.
Margins for the layer. Can be used to make the layer larger or smaller than default chart size.
States
Indicates if element is currently active
Indicates if element is disabled
If set, element will toggle specified boolean setting between
true and false when clicked/touchedData
Allows binding element’s settings to data
Export
If set to
false this element will not appear in exported snapshots of the chartLayout
If set to
false element will not be measured and cannot participate in layout schemesFormatters
An instance of NumberFormatter that should be used instead of global formatter object
An instance of DateFormatter that should be used instead of global formatter object
An instance of DurationFormatter that should be used instead of global formatter object
Accessibility
Can element be focused, i.e. selected using TAB key
An internal order by which focusable elements will be selected within the chart
An identifier by which to group common elements into focusable groups
Simulate hover on an element when it gains focus, including changing hover appearance and displaying a tooltip
If set, the text will be read out (announced) by a screen reader when focused element is “clicked”
Element’s role
Label for the element to use for screen readers
aria-live settingaria-checked settingaria-current settingaria-selected settingaria-hidden settingaria-orientation settingaria-valuenow settingaria-valuemin settingaria-valuemax settingaria-valuetext settingaria-controls settingMethods
show()
Shows currently hidden element.Animation duration in milliseconds
Promise that resolves when animation completes
hide()
Hides currently visible element.Animation duration in milliseconds
Promise that resolves when animation completes
isHidden()
Returnstrue if element is currently hidden.
Whether element is hidden
isVisibleDeep()
Returnstrue if element and all its parents are visible.
Whether element is visible
showTooltip()
Shows element’s Tooltip.Optional point coordinates
Promise that resolves when tooltip is shown
hideTooltip()
Hides element’s Tooltip.Promise that resolves when tooltip is hidden
getTooltip()
Returns Tooltip used for this element.Tooltip instance
hover()
Simulate hover over element.unhover()
Simulate unhover over element.isHover()
Returnstrue if element is currently hovered.
Whether element is hovered
dragStart()
Initiates drag operation.Pointer event
dragStop()
Stops drag operation.Pointer event
dragMove()
Handles drag move.Pointer event
isDragging()
Returnstrue if element is currently being dragged.
Whether element is being dragged
x()
Returns element’s actual X position in pixels.X position in pixels
y()
Returns element’s actual Y position in pixels.Y position in pixels
width()
Returns element’s width in pixels.Width in pixels
height()
Returns element’s height in pixels.Height in pixels
globalBounds()
Returns global coordinates of the element’s bounds.Bounds object with left, right, top, bottom properties
localBounds()
Returns local coordinates of the element’s bounds.Bounds object with left, right, top, bottom properties
depth()
Returns depth (how deep in the hierarchy of the content tree) of this element.Depth level
toGlobal()
Converts local coordinates to global.Local point
Global point
toLocal()
Converts global coordinates to local.Global point
Local point
markDirty()
Marks element as dirty, triggering re-render.markDirtyBounds()
Marks element’s bounds as dirty.markDirtyPosition()
Marks element’s position as dirty.markDirtyAccessibility()
Marks element’s accessibility settings as dirty.Events
Invoked when element is clicked or tapped
Invoked when element is clicked with the right mouse button
Invoked when element is clicked with the middle mouse button
Invoked when element is double-clicked or tapped twice quickly
Invoked when pointer moves over the element
Invoked when pointer moves outside the element
Invoked when pointer button is pressed or touch starts over the element
Invoked when pointer button is released or touch stops over the element
Invoked when pointer button is released anywhere in the window
Invoked when pointer is moving anywhere in the window
Invoked when element dragging starts
Invoked when element dragging stops
Invoked when element is being dragged
Invoked when mouse wheel is spinned while pointer is over the element
Invoked when element gains focus
Invoked when element loses focus
Invoked when element’s position (X/Y) changes
Invoked when element’s bounds change due to any manipulation to it
Invoked when element’s data item changes