Docs
Hooks
useECharts

useECharts

For scenarios demanding finer control over the rendering container or direct access to the echartsInstance, the useECharts hook is at your disposal.

This specialized hook empowers developers with a more granular level of control, offering the flexibility needed for advanced customization.

Usage

export const EChart: FC<UseEChartsOptions> = props => {
  const [ref, echartsInstance] = useECharts<HTMLDivElement>({
    xAxis: {
      type: 'category',
      boundaryGap: false,
      data: ['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun']
    },
    yAxis: {
      type: 'value'
    },
    series: [
      {
        data: [150, 230, 224, 218, 135, 147, 260],
        type: 'line',
        areaStyle: {}
      }
    ]
  })
 
  return <div ref={ref} />
}

API

type UseECharts<T extends HtmlElement> = (
  options: UseEChartsOptions
) => [(node: T) => void, ECharts | undefined]

UseEChartsOptions

The following options can be passed down to the component:

init (opens in a new tab)

PropDescriptionTypeDefault
devicePixelRatioRatio of one physical pixel to the size of one device independent pixelsnumberundefined
heightSpecify height explicitly, in pixel. If setting to null/undefined/'auto', height of dom (instance container) will be usednumber or stringundefined
widthSpecify width explicitly, in pixel. If setting to null/undefined/'auto', width of dom (instance container) will be usednumber or stringundefined
groupGroup name to be used in chart connection.stringundefined
localeSpecify the localestringundefined
pointerSizeSize of expanded interaction size in pixelsnumberundefined
rendererSupports 'canvas' or 'svg'stringsvg
themeTheme to be applied. This can be a configuring object of a theme, or a theme name registeredstringundefined
useCoarsePointerWhether to expand the response area when interacting with elementsbooleanundefined
useDirtyRectEnable dirty rectangle rendering or notbooleanfalse

setOption (opens in a new tab)

PropDescriptionTypeDefault
lazyUpdateWhether or not to update chart immediately;booleanfalse
notMergeWhether or not to merge with previous optionbooleanfalse
replaceMergeWhether or not to merge with previous optionstring, string[]false
silentWhether not to prevent triggering events when calling setOptionbooleanfalse
transitionUpdateLifecycleTransitionOpt``undefined

option (opens in a new tab)

PropDescriptionTypeDefault
angleAxis (opens in a new tab)The angle axis in Polar Coordinateobjectundefined
animation (opens in a new tab)Whether to enable animationobjectundefined
animationDelay (opens in a new tab)Delay before updating the first animation, which supports callback function for different data to have different animation effect.objectundefined
animationDuration (opens in a new tab)Duration of the first animation, which supports callback function for different data to have different animation effectobjectundefined
animationDurationUpdate (opens in a new tab)Time for animation to complete, which supports callback function for different data to have different animation effectobjectundefined
animationEasing (opens in a new tab)Easing method used for the first animation.objectundefined
animationThreshold (opens in a new tab)Whether to set graphic number threshold to animation. Animation will be disabled when graphic number is larger than threshold.objectundefined
aria (opens in a new tab)Descriptionobjectundefined
backgroundColor (opens in a new tab)Background color. No background by default.objectundefined
blendMode (opens in a new tab)Sets the type of compositing operation to apply when drawing a new shape.objectundefined
brush (opens in a new tab)Area-selecting component, with which user can select part of data from a chart to display in detail, or do calculations with them.objectundefined
calendar (opens in a new tab)Calendar coordinatesobjectundefined
color (opens in a new tab)The color list of palette. If no color is set in series, the colors would be adopted sequentially and circularly from this list as the colors of seriesobjectundefined
dataset (opens in a new tab)brings convenience in data management separated with styles and enables data reuse by different series. More importantly, it enables data encoding from data to visual, which brings convenience in some scenarios.objectundefined
dataZoom (opens in a new tab)used for zooming a specific area, which enables user to investigate data in detail, or get an overview of the data, or get rid of outlier pointsobjectundefined
geo (opens in a new tab)Descriptionobjectundefined
graphic (opens in a new tab)Descriptionobjectundefined
grid (opens in a new tab)Drawing grid in rectangular coordinate. In a single grid, at most two X and Y axes each is allowedobjectundefined
hoverLayerThreshold (opens in a new tab)When the number of element of the whole chart is larger than hoverLayerThreshold, a separate hover layer is used to render hovered elements.objectundefined
legend (opens in a new tab)Legend componentobjectundefined
media (opens in a new tab)Descriptionobjectundefined
parallel (opens in a new tab)Common way of visualizing high-dimensional geometry and analyzing multivariate dataobjectundefined
parallelAxis (opens in a new tab)This component is the coordinate axis for parallel coordinateobjectundefined
polar (opens in a new tab)Polar coordinate can be used in scatter and line chart. Every polar coordinate has an angleAxis and a radiusAxis.objectundefined
radar (opens in a new tab)Coordinate for radar chartsobjectundefined
radiusAxis (opens in a new tab)Radial axis of polar coordinateobjectundefined
series (opens in a new tab)""objectundefined
singleAxis (opens in a new tab)An axis with a single dimension. It can be used to display data in one dimensionobjectundefined
textStyle (opens in a new tab)Global font styleobjectundefined
timeline (opens in a new tab)rovides functions like switching and playing between multiple ECharts optionsobjectundefined
title (opens in a new tab)Title component, including main title and subtitleobjectundefined
tooltip (opens in a new tab)Tooltip componentobjectundefined
useUTC (opens in a new tab)Whether to use UTC in displayobjectundefined
visualMap (opens in a new tab)Component for visual encoding, which maps the data to visual channelsobjectundefined
xAxis (opens in a new tab)The x axis in cartesian (rectangular) coordinateobjectundefined
yAxis (opens in a new tab)The y axis in cartesian (rectangular) coordinateobjectundefined

events (opens in a new tab)

PropDescriptionTypeDefault
onAxisAreaSelected (opens in a new tab)Selecting event of range of parallel axis.functionundefined
onBrush (opens in a new tab)Event triggered after action brush dispatched.functionundefined
onBrushEnd (opens in a new tab)Event triggered after action brushEnd dispatched.functionundefined
onBrushSelected (opens in a new tab)Notice what are selected.functionundefined
onClick (opens in a new tab)Event of chart click.functionundefined
onContextMenu (opens in a new tab)Event of context menufunctionundefined
onDataRangeSelected (opens in a new tab)Event emitted after range is changed in visualMap.functionundefined
onDataViewChanged (opens in a new tab)Changing event of data view tool in toolbox.functionundefined
onDataZoom (opens in a new tab)Event emitted after zooming data area.functionundefined
onDoubleClick (opens in a new tab)Event of double chart click.functionundefined
onDownplay (opens in a new tab)Event of data downplay.functionundefined
onFinished (opens in a new tab)Triggered when render finished, that is, when animation finishedfunctionundefined
onFocusNodeadJacency (opens in a new tab)Adjacent nodes highlight event in graph.functionundefined
onGeoSelectChanged (opens in a new tab)Event emitted after selecting state changes.functionundefined
onGeoSelected (opens in a new tab)Event after selecting.functionundefined
onGeoUnselected (opens in a new tab)Cancels selected event.functionundefined
onGlobalCursorTaken (opens in a new tab)-functionundefined
onGlobalOut (opens in a new tab)Event of global out chartfunctionundefined
onHighlight (opens in a new tab)Event of data highlight.functionundefined
onLegendInverseSelect (opens in a new tab)Event emitted after inversing all legends.functionundefined
onLegendScroll (opens in a new tab)Event when trigger legend scroll.functionundefined
onLegendSelectAll (opens in a new tab)Event emitted after all legends are selected.functionundefined
onLegendSelectChanged (opens in a new tab)Event emitted after legend selecting state changes.functionundefined
onLegendSelected (opens in a new tab)Event emitted after legend is selected.functionundefined
onLegendUnselected (opens in a new tab)Event emitted after unselecting legend.functionundefined
onMagicTypeChanged (opens in a new tab)Switching event of magic type tool in toolbox.functionundefined
onMount (opens in a new tab)Callback to be called on first component mount.functionundefined
onMouseDown (opens in a new tab)Event of mouse down chartfunctionundefined
onMouseMove (opens in a new tab)Event of mouse mouse chartfunctionundefined
onMouseOut (opens in a new tab)Event of global out chartfunctionundefined
onMouseOver (opens in a new tab)Event of mouse over chartfunctionundefined
onMouseUp (opens in a new tab)Event of mouse up chartfunctionundefined
onRendered (opens in a new tab)Trigger when a frame rendered. Notice that the rendered event does not indicate that the animation finishedfunctionundefined
onRestore (opens in a new tab)Resets option event.functionundefined
onSelectChanged (opens in a new tab)Event emitted when data selection is changed.functionundefined
onTimelineChanged (opens in a new tab)Event emitted after time point in timeline is changed.functionundefined
onTimelinePlayChanged (opens in a new tab)Switching event of play state in timeline.functionundefined
onUnfocusNodeAdjacency (opens in a new tab)Adjacent nodes reverse-highlight event in graph.functionundefined