2.0.0 • Published 2 years ago

@hcorta/react-echarts v2.0.0

Weekly downloads
21
License
MIT
Repository
github
Last release
2 years ago

React ECharts Header

A React component for the ECharts library

Version Size NPM Dependencies Status


Table of Contents

Installation

In order to use react-echarts, all you need to do is install the npm package:

yarn add @hcorta/react-echarts

echarts and react are peerDependencies of react-echarts, you may install your own versions.

Introduction

Apache ECharts is a free, powerful charting and visualization library offering intuitive, interactive, and highly customizable charts. It is written in pure JavaScript and based on zrender, a canvas library.

react-echarts is an abstraction wrapper built with React on top of Apache ECharts. Its main principles of are:

  1. Simplicty: react-echarts makes it easy to generate ECharts components by wrapping the code required to interact with the core library.
  2. Declarative: components are purely presentational.

Usage

<EChart />

To start using react-echarts, you just need to import the <EChart /> component from the root folder. Check the props section out for more info:

import { EChart } from '@hcorta/react-echarts'

function MyChart() {
  return (
    <EChart
      className={'my-classname'}
      xAxis={{
        type: 'category'
      }}
      yAxis={{
        type: 'value',
        boundaryGap: [0, '30%']
      }}
      series={[
        {
          type: 'line',
          data: [
            ['2022-10-12', 750],
            ['2022-10-17', 300],
            ['2022-10-18', 100]
          ]
        }
      ]}
    />
  )
}

useEcharts

In case you need to have more control over the container being used by the library to render ECharts, a special hook useECharts is provided.

export const EChart: FC<EChartProps> = (props) => {
  const containerRef: Ref<HTMLDivElement> = useRef()

  useECharts({ containerRef, ...props })

  return (
    <div
      ref={containerRef}
      id={id}
    />
  )
}

Props

While some props have been provided to facilitate specific use cases, most of them follow the Apache ECharts option schema. The following props, grouped by category, are available:

General

PropTypeDescriptionDefault
id{String}id of the container''
className{String}Classname of the container''
style{Object}Style object applied to the containernull

ECharts

PropTypeDescriptionDefault
notMerge{Boolean}Whether or not to merge with previous optionfalse
lazyUpdate{Boolean}Whether or not to update chart immediately;false
theme{String}Theme to be applied. This can be a configuring object of a theme, or a theme name registered''
group{String}Group name to be used in chart connection.''
renderer{String}Supports 'canvas' or 'svg''svg'

Option keys props

PropTypeDescriptionDefault
title{Object}https://echarts.apache.org/option.html#titlenull
legend{Object}https://echarts.apache.org/option.html#legendnull
grid{Object}https://echarts.apache.org/option.html#gridnull
xAxis{Object}https://echarts.apache.org/option.html#xAxisnull
yAxis{Object}https://echarts.apache.org/option.html#yAxisnull
polar{Object}https://echarts.apache.org/option.html#polarnull
radiusAxis{Object}https://echarts.apache.org/option.html#radiusAxisnull
angleAxis{Object}https://echarts.apache.org/option.html#angleAxisnull
radar{Object}https://echarts.apache.org/option.html#radarnull
dataZoom{Object}https://echarts.apache.org/option.html#dataZoomnull
visualMap{Object}https://echarts.apache.org/option.html#visualMapnull
tooltip{Object}https://echarts.apache.org/option.html#tooltipnull
brush{Object}https://echarts.apache.org/option.html#brushnull
geo{Object}https://echarts.apache.org/option.html#geonull
parallel{Object}https://echarts.apache.org/option.html#parallelnull
parallelAxis{Object}https://echarts.apache.org/option.html#parallelAxisnull
singleAxis{Object}https://echarts.apache.org/option.html#singleAxisnull
timeline{Object}https://echarts.apache.org/option.html#timelinenull
graphic{Object}https://echarts.apache.org/option.html#graphicnull
calendar{Object}https://echarts.apache.org/option.html#calendarnull
dataset{Object}https://echarts.apache.org/option.html#datasetnull
aria{Object}https://echarts.apache.org/option.html#arianull
series{Object}https://echarts.apache.org/option.html#seriesnull
color{Object}https://echarts.apache.org/option.html#colornull
backgroundColor{Object}https://echarts.apache.org/option.html#backgroundColornull
textStyle{Object}https://echarts.apache.org/option.html#textStylenull
animation{Object}https://echarts.apache.org/option.html#animationnull
animationThreshold{Object}https://echarts.apache.org/option.html#animationThresholdnull
animationDuration{Object}https://echarts.apache.org/option.html#animationDurationnull
animationEasing{Object}https://echarts.apache.org/option.html#animationEasingnull
animationDelay{Object}https://echarts.apache.org/option.html#animationDelaynull
animationDurationUpdate{Object}https://echarts.apache.org/option.html#animationDurationUpdatenull
blendMode{Object}https://echarts.apache.org/option.html#blendModenull
hoverLayerThreshold{Object}https://echarts.apache.org/option.html#hoverLayerThresholdnull
useUTC{Object}https://echarts.apache.org/option.html#useUTCnull
media{Object}https://echarts.apache.org/option.html#medianull

For more detailed info, check the ECharts docs

Events

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

Contributing

No one’s perfect. If you’ve found any errors, want to suggest enhancements, or expand on a topic, please feel free to open an Issue or collaborate by PR.

Code of Conduct

Contributor Code of Conduct. By participating in this project you agree to abide by its terms.

License

react-echarts is open source software licensed as MIT ©hcorta.

2.0.0

2 years ago

1.0.4

2 years ago

1.0.2

2 years ago

1.0.1

2 years ago

1.0.3

2 years ago

1.0.0

3 years ago

0.9.2

3 years ago

0.9.0

3 years ago

0.8.0

3 years ago

0.7.0

3 years ago

0.6.0

3 years ago

0.5.0

3 years ago

0.3.0

3 years ago

0.4.0

3 years ago

0.2.0

3 years ago

0.1.0

3 years ago