Docs ▸ API Reference
const chart = new AbstractChart(container[, options])
- chart.container - D3 selection of the container.
- chart.dispatcher - A
d3-dispatch
event dispatcher for this chart.
- (static) AbstractChart.getCustomEventNames() - return the names of custom events that an object of this class can dispatch (other than
resize
,data
andoptions
that are included with every AbstractChart). - chart.getCustomEventNames() - return the names of custom events that this chart can dispatch (other than
resize
,data
andoptions
that are included with every AbstractChart). - chart.on(eventName, listener) - add an event listener to an event from this chart.
- chart.off(eventName, listener) - remove an event listener from this chart.
- chart.setupDispatcher(customEventNames) - setup the dispatcher to include the specified custom event names.
- chart.dispatchAs(name) - Returns an event handler that will capture all arguments and dispatch as event
name
.
- (static) AbstractChart.getDefaultOptions() - create and return a default
options
Object. Overwrite this function when extending the class to modify default options. - chart.data([data]) - get/set the data.
- chart.on('data', listener) - handle when the data are set.
- chart.hasData() - return
true
if data is notnull
orundefined
. - chart.options([options]) - get/set the options.
- chart.on('options', listener) - handle when the options are set.
- chart.dimension([dimension]) - get/set both width and height at the same time.
- chart.fit(fitOptions[, watchOptions]) - Calling this function with single argument will resize the chart to fit into the container once. Calling with two arguments, such as
chart.fit({...}, true)
orchart.fit({...}, {...})
, will enable watching. Please refer to slimfit documentation forfitOptions
andwatchOptions
- chart.getInnerHeight() - return the height of the chart without margin.
- chart.getInnerWidth() - return the width of the chart without margin.
- chart.hasNonZeroArea() - return
true
if the inner area (inner width x inner height) is more than zero. - chart.height([height]) - get/set the height.
- chart.margin([margin]) - get/set the margin.
- chart.offset([offset]) - get/set the offset.
- chart.stopFitWatcher() - stop the watcher.
- chart.updateDimensionNow() - force the chart to recompute the dimension immediately. This is a synchronous operation while other sizing functions are asynchronous.
- chart.width([width]) - get/set the width.
- chart.on('resize', listener) - handle when the dimension is changed.
- chart.addPlate(name, plate[, doNotAppend]) - Add a plate to this chart with the given name. If
doNotAppend
is true, will not append the plate node to this chart node (only keep in memory). - chart.removePlate(name) - Remove a plate with the specified name.
- chart.destroy() - kill all event listeners and watchers. Useful for cleaning up when the chart is not needed anymore.
const chart = new SvgChart(container[, options])
- inherits from
AbstractChart
- chart.layers - return the LayerOrganizer.
- chart.rootG - D3 selection of the root
<g>
element. - chart.svg - D3 selection of the
<svg>
element.
const chart = new CanvasChart(container[, options])
- inherits from
AbstractChart
- chart.canvas - D3 selection of the
<canvas>
element.
- inherits from
AbstractChart
- chart.clear() - clear canvas.
- chart.getContext2d() - return a context for drawing on canvas.
const chart = new HybridChart(container[, options])
- inherits from
CanvasChart
- inherits from
SvgChart
- inherits from
CanvasChart
- inherits from
SvgChart
const plate = new AbstractPlate(node[, options])
- plate.getNode() - returns a DOM node represented by this plate
- plate.getSelection() - returns a D3 selection of the DOM node represented by this plate
const plate = new CanvasPlate(node[, options])
- inherits from
AbstractPlate
- plate.clear() - clear canvas.
- plate.getContext2d() - return a context for drawing on canvas.
const plate = new DivPlate(node[, options])
- inherits from
AbstractPlate
const plate = new SvgPlate(node[, options])
- inherits from
AbstractPlate
const layers = new LayerOrganizer(container[, defaultTag])
- layers.create(config) - create layers of element, such as
<g>
, within the container. - layers.get(name) - get a layer by name.
- layers.has(name) - check if there is a layer with specified name.
- (static) helper.debounce(func, delay)
- (static) helper.deepExtend(dest, src1, src2, ...)
- (static) helper.extend(dest, src1, src2, ...)
- (static) helper.functor(valueOrFunc)
- (static) helper.isFunction(value)
- (static) helper.isObject(value)
- (static) helper.kebabCase(string)
- (static) helper.throttle(func, delay)