chart

Configuration Structure

chart: {
width: string | number,
height: string | number,
type: 'line' | 'area' | ...,
foreColor: string,
fontFamily: string,
background: string,
offsetX: number,
offsetY: number,
dropShadow: { ... },
enabled: boolean,
top: number,
left: number,
blur: number,
opacity: number,
color: string | string[],
enabledOnSeries: undefined | number[],
nonce: string,
events: { ... },
animationEnd: Function,
beforeMount: Function,
mounted: Function,
updated: Function,
mouseMove: Function,
mouseLeave: Function,
click: Function,
xAxisLabelClick: Function,
legendClick: Function,
markerClick: Function,
selection: Function,
dataPointSelection: Function,
dataPointMouseEnter: Function,
dataPointMouseLeave: Function,
beforeZoom: Function,
beforeResetZoom: Function,
zoomed: Function,
scrolled: Function,
brushScrolled: Function,
keyDown: Function,
keyUp: Function,
brush: { ... },
enabled: boolean,
autoScaleYaxis: boolean,
target: string,
targets: string[],
id: string,
injectStyleSheet: boolean,
group: string,
locales: ApexLocale[],
name: string,
options: { ... },
months: string[],
shortMonths: string[],
days: string[],
shortDays: string[],
toolbar: { ... },
download: string,
selection: string,
selectionZoom: string,
zoomIn: string,
zoomOut: string,
pan: string,
reset: string,
exportToSVG: string,
exportToPNG: string,
exportToCSV: string,
defaultLocale: string,
parentHeightOffset: number,
redrawOnParentResize: boolean,
redrawOnWindowResize: boolean | ((args: any[]) => boolean),
sparkline: { ... },
enabled: boolean,
stacked: boolean,
stackType: 'normal' | '100%',
stackOnlyBar: boolean,
toolbar: { ... },
show: boolean,
offsetX: number,
offsetY: number,
tools: { ... },
download: boolean | string,
selection: boolean | string,
zoom: boolean | string,
zoomin: boolean | string,
zoomout: boolean | string,
pan: boolean | string,
reset: boolean | string,
customIcons: Array,
icon: string,
title: string,
index: number,
class: string,
click: Function,
export: { ... },
csv: { ... },
filename: undefined | string,
columnDelimiter: string,
headerCategory: string,
headerValue: string,
categoryFormatter: Function,
valueFormatter: Function,
svg: { ... },
filename: undefined | string,
png: { ... },
filename: undefined | string,
width: number,
scale: number,
autoSelected: 'zoom' | 'selection' | 'pan',
zoom: { ... },
enabled: boolean,
type: 'x' | 'y' | 'xy',
autoScaleYaxis: boolean,
allowMouseWheelZoom: boolean,
zoomedArea: { ... },
fill: { ... },
color: string,
opacity: number,
stroke: { ... },
color: string,
opacity: number,
width: number,
selection: { ... },
enabled: boolean,
type: string,
fill: { ... },
color: string,
opacity: number,
stroke: { ... },
width: number,
color: string,
opacity: number,
dashArray: number,
xaxis: { ... },
min: number,
max: number,
yaxis: { ... },
min: number,
max: number,
animations: { ... },
enabled: boolean,
speed: number,
animateGradually: { ... },
enabled: boolean,
delay: number,
dynamicAnimation: { ... },
enabled: boolean,
speed: number,
accessibility: { ... },
enabled: boolean,
description: string,
announcements: { ... },
enabled: boolean,
keyboard: { ... },
enabled: boolean,
navigation: { ... },
enabled: boolean,
wrapAround: boolean,
dataReducer: { ... },
enabled: boolean,
algorithm: 'lttb',
targetPoints: number,
threshold: number,
}

chart

width

Default: '100%'

Width of the chart. Accepts Number (400) which is treated as pixels or String ('400px' or '100%')

height

Default: 'auto'

Height of the chart. The default value 'auto' is calculated based on the golden ratio 1.618 which makes a height roughly 61.8% of its width. Accepts Number (400) or String ('400px' or '100%')

type

Default: 'line'

Specify the chart type. Available options:

  • line
  • area
  • bar
  • pie
  • donut
  • radialBar
  • scatter
  • bubble
  • heatmap
  • candlestick
  • boxPlot
  • radar
  • polarArea
  • rangeBar
  • rangeArea
  • treemap

foreColor

Default: '#373d3f'

Sets the text color for the chart. Defaults to #373d3f.

fontFamily

Default: 'Helvetica, Arial, sans-serif'

Sets the font family for all text elements of the chart. Defaults to 'Helvetica, Arial, sans-serif'

background

Default: ''

Background color for the chart area. If you want to set background with css, use .apexcharts-canvas to set it.

offsetX

Default: 0

Sets the left offset for the entire chart.

offsetY

Default: 0

Sets the top offset for the entire chart.

dropShadow

enabled

chart.dropShadow.enabled
Default: false

Enable a dropshadow for paths of the SVG

enabledOnSeries

chart.dropShadow.enabledOnSeries
Default: undefined

Provide series index on which the dropshadow should be enabled.

top

chart.dropShadow.top
Default: 2

Set top offset for shadow

left

chart.dropShadow.left
Default: 2

Set left offset for shadow

blur

chart.dropShadow.blur
Default: 4

Set blur distance for shadow

color

chart.dropShadow.color
Default: '#000'

Give a color to the shadow. If array is provided, each series can have different shadow color

opacity

chart.dropShadow.opacity
Default: 0.7

Set the opacity of shadow.

nonce

Default: undefined

Nonce attribute added to the style tag for CSP (Content Security Policy). If set, the nonce will be appended to the style tag.

id

Default: undefined

A chart ID is a unique identifier that will be used in calling certain ApexCharts methods. Also used in group option to sync charts. You will also need chart.id to be set in case you use updateOptions() or exec() methods.

group

Default: undefined

Setting chart.group with a common name for multiple charts will sync the tooltip, panning, and zooming across all charts with the same group name. Each chart needs to have a unique chart.id.

Example:

// Chart 1
var chart1 = new ApexCharts(el, {
  chart: {
    id: 'chart1',
    group: 'social',
  }
})

// Chart 2
var chart2 = new ApexCharts(el, {
  chart: {
    id: 'chart2',
    group: 'social',
  }
})

defaultLocale

Default: 'en'

Use this option to set the default locale. Requires the locales array to have the locale data for that locale name.

locales

name

chart.locales.name

Name of the locale you will be defining options for. Can be en, fr, etc.

options

chart.locales.options

months

chart.locales.options.months
Default: ['January', ..., 'December']

Full month names in your preferred language

shortMonths

chart.locales.options.shortMonths
Default: ['Jan', ..., 'Dec']

Abbreviations of months

days

chart.locales.options.days
Default: ['Sunday', ..., 'Saturday']

Full names of days in your language

shortDays

chart.locales.options.shortDays
Default: ['Sun', ..., 'Sat']

Abbreviated day names

toolbar

chart.locales.options.toolbar

download

chart.locales.options.toolbar.download
Default: 'Download SVG'

Tooltip title text which appears when you hover over download icon

selection

chart.locales.options.toolbar.selection
Default: 'Selection'

Tooltip title text which appears when you hover over selection icon

selectionZoom

chart.locales.options.toolbar.selectionZoom
Default: 'Selection Zoom'

Tooltip title text which appears when you hover over selection zoom icon

zoomIn

chart.locales.options.toolbar.zoomIn
Default: 'Zoom In'

Tooltip title text which appears when you hover over zoom in icon

zoomOut

chart.locales.options.toolbar.zoomOut
Default: 'Zoom Out'

Tooltip title text which appears when you hover over zoom out icon

pan

chart.locales.options.toolbar.pan
Default: 'Panning'

Tooltip title text which appears when you hover over pan icon

reset

chart.locales.options.toolbar.reset
Default: 'Reset Zoom'

Tooltip title text which appears when you hover over reset icon

parentHeightOffset

Default: 15

A small padding is applied to the bottom of the chart area to make the chart look neat. You may not need this in case you set a fixed height. This is useful if you have a sparkline chart in a small container.

redrawOnParentResize

Default: true

Re-render the chart when the element is resized. Useful if a chart is rendered in a dynamically sized container.

redrawOnWindowResize

Default: true

Re-render the chart when the window is resized. Useful in cases where auto-resizing on window resize may cause issues.

sparkline

enabled

chart.sparkline.enabled
Default: false

sparkline hides all the elements of the charts other than the primary paths. Helps to visualize data in small areas. See example

stacked

Default: false

Enables stacked option for axis charts. See example

stackType

Default: 'normal'

When stacked, should the stacking be percentage based or normal stacking. Available options:

  • 'normal'
  • '100%'

stackOnlyBar

Default: true

When using a combo chart (line and bar together), stack only the bar series and leave the line series unstacked.

toolbar

show

chart.toolbar.show
Default: true

Display the toolbar / menu in the top right corner.

offsetX

chart.toolbar.offsetX
Default: 0

Sets the left offset of the toolbar.

offsetY

chart.toolbar.offsetY
Default: 0

Sets the top offset of the toolbar.

tools

chart.toolbar.tools

download

chart.toolbar.tools.download
Default: true

hamburger-icon

Show the download menu / hamburger icon in the toolbar. If you want to display a custom icon instead of hamburger icon, you can provide HTML string in this property.


download: true
/* OR */
download: '<img src="/static/icons/download.png" class="ico-download" width="20">'

ApexCharts has built-in support to allow exporting the chart to popular image formats like PNG or SVG and also allows exporting the chart data to a CSV file.

By default, all XY charts have the toolbar enabled in them which has a hamburger icon at the top right corner. Clicking the hamburger icon opens a menu which has following options to download

apexcharts-export-svg-png-csv

  • Export to SVG
  • Export to PNG
  • Export to CSV creates a comma separated values file, which consists of chart data.

selection

chart.toolbar.tools.selection
Default: true

Show the rectangle selection icon in the toolbar. If you want to display a custom icon for selection, you can provide HTML string in this property.

Make sure to also enable chart.selection when showing the selection tool.


chart: {
  selection: {
    enabled: true
  }
}

zoom

chart.toolbar.tools.zoom
Default: true

Show the zoom icon which is used for zooming by dragging selection on the chart area. If you want to display a custom icon for zoom, you can provide HTML string in this property.

zoomin

chart.toolbar.tools.zoomin
Default: true

Show the zoom-in icon which zooms in 50% from the visible chart area. If you want to display a custom icon for zoom-in, you can provide HTML string in this property.

zoomout

chart.toolbar.tools.zoomout
Default: true

Show the zoom-out icon which zooms out 50% from the visible chart area. If you want to display a custom icon for zoom-out, you can provide HTML string in this property.

pan

chart.toolbar.tools.pan
Default: true

Show the panning icon in the toolbar.

reset

chart.toolbar.tools.reset
Default: true

Reset the chart data to it's initial state after zommin/zoomout/panning. If you want to display a custom icon for reset, you can provide HTML string in this property.

customIcons

chart.toolbar.tools.customIcons

Allows to add additional icon buttons in the toolbar. In the below example, index should be used to place at a particular position in the toolbar.


customIcons: [{
icon: '<img src="/static/icons/chart-carpet.png" width="20">',
index: 4,
title: 'tooltip of the icon',
class: 'custom-icon',
click: function (chart, options, e) {
  console.log("clicked custom-icon")
}
}]

export

chart.toolbar.export

scale

chart.toolbar.export.scale

Scale the exported image. Example: scale: 0.5 or scale: 2

width

chart.toolbar.export.width

Provide a fixed width of the exported image. Don't append unit to the number, just provide a numeric value, it will be considered in px.

csv

chart.toolbar.export.csv

filename

chart.toolbar.export.csv.filename

Name of the csv file. Defaults to auto generated chart ID

columnDelimiter

chart.toolbar.export.csv.columnDelimiter
Default: ','

Delimeter to separate data-items. Defaults to comma.

headerCategory

chart.toolbar.export.csv.headerCategory
Default: 'category'

Column Title of X values

headerValue

chart.toolbar.export.csv.headerValue
Default: 'value'

Column Title of Y values

categoryFormatter

chart.toolbar.export.csv.categoryFormatter

Format the x values when exporting to CSV.

valueFormatter

chart.toolbar.export.csv.valueFormatter

Format the y values when exporting to CSV.

svg

chart.toolbar.export.svg

filename

chart.toolbar.export.svg.filename

Name of the SVG file. Defaults to auto generated chart ID

png

chart.toolbar.export.png

filename

chart.toolbar.export.png.filename

Name of the PNG file. Defaults to auto generated chart ID

autoSelected

chart.toolbar.autoSelected
Default: 'zoom'

Automatically select one of the following tools when the chart loads.

  • zoom
  • selection
  • pan

zoom

enabled

chart.zoom.enabled
Default: true

To allow zooming in axis charts.

Note: In a category x-axis chart, to enable zooming, you will also need to set xaxis.tickPlacement: 'on'.

Read more on the Category Axis Zoom tutorial.

type

chart.zoom.type
Default: 'x'

Allow zooming either on both x-axis, y-axis or on both axis. Available options

  • x
  • y
  • xy

Known Issue: In synchronized charts, xy or y will not update charts in sync, while x will work correctly.

autoScaleYaxis

chart.zoom.autoScaleYaxis
Default: false

When this option is turned on, the chart's y-axis re-scales to a new low and high based on the visible area. Helpful in situations where the user zoomed in to a small area to get a better view.

Known Issue: This option doesn't work in a multi-axis chart (when you have more than 1 y-axis)

allowMouseWheelZoom

chart.zoom.allowMouseWheelZoom
Default: true

Whether to allow zooming using mouse wheel.

zoomedArea

chart.zoom.zoomedArea

zoomedArea is the area which is drawn when a user drags the mouse from one point to another Zoomed area

fill

chart.zoom.zoomedArea.fill

color

chart.zoom.zoomedArea.fill.color
Default: '#90CAF9'

Background color of the selection zoomed area

opacity

chart.zoom.zoomedArea.fill.opacity
Default: 0.4

Sets the transparency level of the selection fill

stroke

chart.zoom.zoomedArea.stroke

color

chart.zoom.zoomedArea.stroke.color
Default: '#0D47A1'

Border color of the selection zoomed area

opacity

chart.zoom.zoomedArea.stroke.opacity
Default: 0.4

Sets the transparency level of the selection border

width

chart.zoom.zoomedArea.stroke.width
Default: 1

Sets the width selection border

selection

enabled

chart.selection.enabled
Default: false

To allow selection in axis charts. Selection will not be enabled for category x-axis charts, but only for charts having numeric x-axis. For eg., timeline charts.

type

chart.selection.type
Default: 'x'

Allow selection either on both x-axis, y-axis or on both axis. Available options

  • x
  • y
  • xy

fill

chart.selection.fill

color

chart.selection.fill.color
Default: '#24292e'

Background color of the selection rect which is drawn when user drags on the chart.

opacity

chart.selection.fill.opacity
Default: 0.1

Opacity of background color of the selection rect.

stroke

chart.selection.stroke

width

chart.selection.stroke.width
Default: 1

Border thickness of the selection rect.

dashArray

chart.selection.stroke.dashArray
Default: 3

Creates dashes in borders of svg path. Higher number creates more space between dashes in the border.

color

chart.selection.stroke.color
Default: '#24292e'

Colors of selection border.

opacity

chart.selection.stroke.opacity
Default: 0.4

Opacity of selection border.

xaxis

chart.selection.xaxis

min

chart.selection.xaxis.min
Default: undefined

Start value of x-axis. For a time-series chart, a timestamp should be provided

max

chart.selection.xaxis.max
Default: undefined

End value of x-axis. For a time-series chart, a timestamp should be provided.

yaxis

chart.selection.yaxis

min

chart.selection.yaxis.min
Default: undefined

Start value of y-axis. (if used in a multiple y-axes chart, this considers the 1st y-axis).

max

chart.selection.yaxis.max
Default: undefined

End value of y-axis (if used in a multiple y-axes chart, this considers the 1st y-axis).

animations

enabled

chart.animations.enabled
Default: true

Enable or disable all the animations that happen initially or during data update.

speed

chart.animations.speed
Default: 800

Speed at which animation runs.

animateGradually

chart.animations.animateGradually

enabled

chart.animations.animateGradually.enabled
Default: true

Gradually animate one by one every data in the series instead of animating all at once.

delay

chart.animations.animateGradually.delay
Default: 150

Speed at which gradual (one by one) animation runs.

dynamicAnimation

chart.animations.dynamicAnimation

enabled

chart.animations.dynamicAnimation.enabled
Default: true

Animate the chart when data is changed and chart is re-rendered.

speed

chart.animations.dynamicAnimation.speed
Default: 350

Speed at which dynamic animation runs whenever data changes.

brush

enabled

chart.brush.enabled
Default: false

Turn on this option to enable brush chart options. After you enable brush, you need to set target chart ID to allow the brush chart to capture events on the target chart.

target

chart.brush.target
Default: undefined

Chart ID of the target chart to sync the brush chart and the target chart. If you have an array of multiple chart IDs, use targets property instead.

autoScaleYaxis

chart.brush.autoScaleYaxis
Default: true

If set to true, the Y-axis will automatically scale based on the visible min/max range.

Note: One important configuration to set in a brush chart is the chart.selection option. The range which you set in chart.selection will act as brush in the brush chart

Here's an example code snippet how brush/target works


var targetChartOptions = {
  chart: {
    id: 'target-chart',
    type: 'line',
    height: 230,
    toolbar: {
      autoSelected: 'pan',
      show: false
    }
  },
}

var brushChartOptions = {
  chart: {
    height: 130,
    type: 'area',
    brush:{
      target: 'chart2',
      enabled: true
    },
    selection: {
      xaxis: {
        min: new Date('19 Jun 2017').getTime(),
        max: new Date('14 Aug 2017').getTime()
      }
    },
  },
}

And, here you will find a complete example of brush charts usage Brush chart demo.

events

animationEnd

chart.events.animationEnd

Fires when the chart's initial animation is finished

chart: { events: { animationEnd: function (chartContext, options) { // ... } } }

beforeMount

chart.events.beforeMount

Fires before the chart has been drawn on screen

chart: { events: { beforeMount: function (chartContext, config) { // ... } } }

mounted

chart.events.mounted

Fires after the chart has been drawn on screen

chart: { events: { mounted: function(chartContext, config) { // ... } } }

updated

chart.events.updated

Fires when the chart has been dynamically updated either with updateOptions() or updateSeries() functions

chart: { events: { updated: function(chartContext, config) { // ... } } }

click

chart.events.click

Fires when user clicks on any area of the chart.

chart: { events: { click: function(event, chartContext, opts) { // The last parameter opts contains additional information like `seriesIndex` and `dataPointIndex` for cartesian charts } } }

mouseMove

chart.events.mouseMove

Fires when user moves mouse on any area of the chart.

chart: { events: { mouseMove: function(event, chartContext, opts) { // The last parameter opts contains additional information like `seriesIndex` and `dataPointIndex` for cartesian charts. } } }

mouseLeave

chart.events.mouseLeave

Fires when user moves mouse outside chart area (exclusing axis).

chart: { events: { mouseLeave: function(event, chartContext, opts) { // ... } } }

legendClick

chart.events.legendClick

Fires when user clicks on legend.

chart: { events: { legendClick: function(chartContext, seriesIndex, opts) { // ... } } }

markerClick

chart.events.markerClick

Fires when user clicks on the markers.

chart: { events: { markerClick: function(event, chartContext, opts) { // ... } } }

xAxisLabelClick

chart.events.xAxisLabelClick

Fires when user clicks on the x-axis labels.

chart: { events: { xAxisLabelClick: function(event, chartContext, opts) { // ... } } }

selection

chart.events.selection

Fires when user selects rect using the selection tool. The second argument contains the yaxis and xaxis coordinates where user made the selection

chart: { events: { selection: function(chartContext, { xaxis, yaxis }) { // ... } } }

dataPointSelection

chart.events.dataPointSelection

Fires when user clicks on a datapoint (bar/column/marker/bubble/donut-slice). The third argument (opts) also includes additional information like which dataPointIndex was selected of which series. If you have allowMultipleDataPointsSelection enabled, the third argument includes selectedDataPoints property to get all selected dataPoints.

Note: When using in line/area charts, this event requires tooltip.intersect: true & tooltip.shared: false along with markers.size has to be greater than 0.

chart: { events: { dataPointSelection: function(event, chartContext, opts) { // ... } } }

dataPointMouseEnter

chart.events.dataPointMouseEnter

Fires when user's mouse enter on a datapoint (bar/column/marker/bubble/donut-slice). The third argument also includes additional information like which dataPointIndex was hovered of particular series.

Note: When using in line/area charts, this event requires tooltip.intersect: true & tooltip.shared: false along with markers.size has to be greater than 0

chart: { events: { dataPointMouseEnter: function(event, chartContext, opts) { // ... } } }

dataPointMouseLeave

chart.events.dataPointMouseLeave

MouseLeave event for a datapoint (bar/column/marker/bubble/donut-slice).

chart: { events: { dataPointMouseLeave: function(event, chartContext, opts) { // ... } } }

beforeZoom

chart.events.beforeZoom

This function, if defined, runs just before zooming in/out of the chart allowing you to set a custom range for zooming in/out.


  beforeZoom: function(chartContext, { xaxis }) {
    return {
      xaxis: {
        min: timestamp,
        max: timestamp
      }
    }
  }

The range which is returned in the beforeZoom function is used for the next zoom event.

beforeResetZoom

chart.events.beforeResetZoom

This function, if defined, runs just before the user hits the HOME button on the toolbar to reset the chart to it's original state. The function allows you to set a custom axes range for the initial view of the chart.


  beforeResetZoom: function(chartContext, opts) {
    return {
      xaxis: {
        min: timestamp,
        max: timestamp
      }
    }
  }

The range which is returned in the beforeResetZoom function is used for resetting the chart axes to it's original state.

zoomed

chart.events.zoomed

Fires when user zooms in/out the chart using either the selection zooming tool or zoom in/out buttons. The 2nd argument includes information of the new xaxis/yaxis generated after zooming.

chart: { events: { zoomed: function(chartContext, { xaxis, yaxis }) { // ... } } }

scrolled

chart.events.scrolled

Fires when user scrolls using the pan tool. The 2nd argument includes information of the new xaxis generated after scrolling.

chart: { events: { scrolled: function(chartContext, { xaxis }) { // ... } } }

brushScrolled

chart.events.brushScrolled

Fires when user drags the brush in a brush chart. The 2nd argument includes information of the new axes generated after scrolling the brush.

chart: { events: { brushScrolled: function(chartContext, { xaxis, yaxis }) { // ... } } }