0.11.0 • Published 1 year ago

react-apexchart-library v0.11.0

Weekly downloads
-
License
MIT
Repository
github
Last release
1 year ago

react-apexchart-library

react + apexchart 를 쉽게 시작하기 위해 제작했습니다.

Easy to get started with react + apexchart.

apexchart 종류 별로 업데이트 예정이며, 현재는 Line Chart, Bar Chart, Area Chart, Bubble Chart, BoxPlot Chart, Candlestick Chart, Heatmap Chart, Pie Chart, PolarArea Chart, Radar Chart, Radial Bar Chart, TreeMap Chart 가 업데이트 된 상태 입니다.

It will be updated for each apexchart type, and the Line Chart, Bar Chart, Area Chart, Bubble Chart, BoxPlot Chart, Candlestick Chart, Heatmap Chart, Pie Chart, PolarArea Chart, Radar Chart, Radial Bar Chart, TreeMap Chart is currently updated.

Download and Installation

Installing via npm
npm i react-apexchart-library

Usage

import {
  LineChart,
  BarChart,
  AreaChart,
  BubbleChart,
  BoxPlotChart,
  CandlestickChart,
  HeatmapChart,
  PieChart,
  PolarAreaChart,
  RadarChart,
  RadialBarChart,
  TreeMapChart,
} from 'react-apexchart-library';

최소한의 구성으로 기본적인 라인 차트 만들려면 아래와 같이 진행하세요.

To create a basic line chart with minimal configuration, proceed as follows:

function App() {
  const chartSeries = [
    {
      name: 'Test Name1',
      data: [10, 30, 50, 70, 90, 10, 30],
    },
    {
      name: 'Test Name2',
      data: [20, 40, 60, 80, 20, 40, 60],
    },
  ];
  const categories = ['test1', 'test2', 'test3', 'test4', 'test5', 'test6', 'test7'];
  return (
    <>
      <LineChart // or <BarChart />, <AreaChart /> ... etc
        chartSeries={chartSeries}
        categories={categories}
      />
    </>
  );
}

export default App;

아래와 같이 차트가 렌더링 됩니다.

This will render the following chart.

image

Bubble Chart 에서는 Series 설정을 다르게 해야 합니다.

In case of Bubble Chart, you need to set the Series differently.

function App() {
  const bubbleRadius = [10, 100];
  const chartSeries = [
    {
      name: 'Bubble1',
      data: [
        [10, 10, 10],
        [20, 20, 20],
        [30, 30, 30],
      ],
    },
    {
      name: 'Bubble2',
      data: [
        [50, 50, 50],
        [60, 60, 60],
        [70, 70, 70],
      ],
    },
    {
      name: 'Bubble3',
      data: [
        [40, 40, 40],
        [80, 80, 80],
        [90, 90, 90],
      ],
    },
    {
      name: 'Bubble4',
      data: [
        [26, 26, 26],
        [73, 73, 73],
        [81, 81, 81],
      ],
    },
  ];

  //* data: [[x: number => xAxis, y: number => yAxis, z: number => size]]
  return (
    <>
      <BubbleChart chartSeries={chartSeries} bubbleRadius={bubbleRadius} dataLabelEnabled={false} />
    </>
  );
}

BoxPlot Chart 에서는 Series 설정을 다르게 해야 합니다.

In case of BoxPlot Chart, you need to set the Series differently.

function App() {
  const chartSeries = [
    {
      data: [
        {
          x: 'Category A',
          y: [54, 66, 69, 75, 88],
        },
        {
          x: 'Category B',
          y: [43, 65, 69, 76, 81],
        },
        {
          x: 'Category C',
          y: [31, 39, 45, 51, 59],
        },
        {
          x: 'Category D',
          y: [39, 46, 55, 65, 71],
        },
        {
          x: 'Category E',
          y: [29, 31, 35, 39, 44],
        },
        {
          x: 'Category F',
          y: [41, 49, 58, 61, 67],
        },
        {
          x: 'Category G',
          y: [54, 59, 66, 71, 88],
        },
      ],
    },
  ];

  //* [{ x: category/date, y: [min, q1, median, q3, max] }]
  return (
    <>
      <BoxPlotChart chartSeries={chartSeries} dataLabelEnabled={false} zoomOptions={{ enabled: false }} />
    </>
  );
}

Candlestick Chart 에서는 Series 설정을 다르게 해야 합니다.

In case of Candlestick Chart, you need to set the Series differently.

function App() {
  const chartSeries = [{
      data: [
        {
          x: new Date(1538778600000),
          y: [6629.81, 6650.5, 6623.04, 6633.33]
        },
        {
          x: new Date(1538780400000),
          y: [6632.01, 6643.59, 6620, 6630.11]
        },
        {
          x: new Date(1538782200000),
          y: [6630.71, 6648.95, 6623.34, 6635.65]
        },
        {
          x: new Date(1538784000000),
          y: [6635.65, 6651, 6629.67, 6638.24]
        },
        {
          x: new Date(1538785800000),
          y: [6638.24, 6640, 6620, 6624.47]
        },
        {
          x: new Date(1538787600000),
          y: [6624.53, 6636.03, 6621.68, 6624.31]
        },
        {
          x: new Date(1538789400000),
          y: [6624.61, 6632.2, 6617, 6626.02]
        },
        {
          x: new Date(1538791200000),
          y: [6627, 6627.62, 6584.22, 6603.02]
        },
        {
          x: new Date(1538793000000),
          y: [6605, 6608.03, 6598.95, 6604.01]
        },
        ...
      ]
    }];

  /*
  The multi-dimensional array:
  [[Timestamp], [O, H, L, C]]

  single array:
  [Timestamp, O, H, L, C]

  xy format:
  [{ x: date, y: [O,H,L,C] }]
  */

  return (
    <>
      <CandlestickChart
        chartSeries={chartSeries}
        dataLabelEnabled={false}
        XAxisOptions={['datetime']}
      />
    </>
  );
}

Heatmap Chart 에서는 Series 설정을 다르게 해야 합니다.

In case of Heatmap Chart, you need to set the Series differently.

function App() {
  const chartSeries = [
    {
      name: 'Metric 1',
      data: [
        {
          x: 'W1',
          y: 22,
        },
        {
          x: 'W2',
          y: 29,
        },
        ...etc,
      ],
    },
    {
      name: 'Metric 2',
      data: [
        {
          x: 'W1',
          y: 22,
        },
        {
          x: 'W2',
          y: 29,
        },
        ...etc,
      ],
    },
    ...etc,
  ];

  const heatmapColorScale = [
    {
      from: 0,
      to: 20,
      name: 'low',
      color: '#2196F3',
    },
    {
      from: 21,
      to: 40,
      name: 'medium',
      color: '#4CAF50',
    },
    {
      from: 41,
      to: 60,
      name: 'high',
      color: '#FFC107',
    },
    {
      from: 61,
      to: 80,
      name: 'extreme',
      color: '#FF5722',
    },
    {
      from: 81,
      to: 100,
      name: 'max',
      color: '#9C27B0',
    },
  ];

  return (
    <>
      <HeatmapChart chartSeries={chartSeries} dataLabelEnabled={false} heatmapColorScale={heatmapColorScale} />
    </>
  );
}

Pie Chart 에서는 Series 설정을 다르게 해야 합니다.

In case of Pie Chart, you need to set the Series differently.

function App() {
  const chartSeries = [44, 55, 13, 43, 22];
  const pieLabels = ['Label1', 'Label2', 'Label3', 'Label4', 'Label5'];

  return (
    <>
      <PieChart chartSeries={chartSeries} pieLabels={pieLabels} />
    </>
  );
}

PolarArea Chart 는 Pie Chart 와 동일합니다.

PolarArea Chart is the same as Pie Chart.

function App() {
  const chartSeries = [44, 55, 13, 43, 22];
  const polarLabels = ['Label1', 'Label2', 'Label3', 'Label4', 'Label5'];

  return (
    <>
      <PolarAreaChart chartSeries={chartSeries} polarLabels={polarLabels} dataLabelEnabled={false} />
    </>
  );
}

Radar Chart 는 Line Chart 와 동일합니다.

Radar Chart is the same as Line Chart.

function App() {
  const chartSeries = [
    {
      name: 'Test Name1',
      data: [10, 30, 50, 70, 90, 10, 30],
    },
    {
      name: 'Test Name2',
      data: [20, 40, 60, 80, 20, 40, 60],
    },
  ];
  const categories = ['test1', 'test2', 'test3', 'test4', 'test5', 'test6', 'test7'];
  return (
    <>
      <RadarChart // or <BarChart />, <AreaChart /> ... etc
        chartSeries={chartSeries}
        categories={categories}
        dataLabelEnabled={false}
      />
    </>
  );
}

Radial Bar Chart 는 Pie Chart 와 동일합니다.

Radial Bar Chart is the same as Pie Chart.

function App() {
  const chartSeries = [10, 30, 50, 70, 90];
  const radialBarLabels = ['test1', 'test2', 'test3', 'test4', 'test5'];
  return (
    <>
      <RadialBarChart chartSeries={chartSeries} radialBarLabels={radialBarLabels} tooltipOptions={[false]} />
    </>
  );
}

TreeMap Chart is the same as Heatmap Chart.

function App() {
  const chartSeries = [
    {
      name: 'Desktops',
      data: [
        {
          x: 'ABC',
          y: 10,
        },
        {
          x: 'DEF',
          y: 60,
        },
        {
          x: 'XYZ',
          y: 41,
        },
      ],
    },
    {
      name: 'Mobile',
      data: [
        {
          x: 'ABCD',
          y: 10,
        },
        {
          x: 'DEFG',
          y: 20,
        },
        {
          x: 'WXYZ',
          y: 51,
        },
        {
          x: 'PQR',
          y: 30,
        },
        {
          x: 'MNO',
          y: 20,
        },
        {
          x: 'CDE',
          y: 30,
        },
      ],
    },
  ];

  return (
    <>
      <TreeMapChart chartSeries={chartSeries} dataLabelTextStyle={{ colors: ['#fff'] }} zoomOptions={{ enabled: false }} />
    </>
  );
}

Props

PropTypeDefaultDescription
chartSeriesArray[]chart data series
chartHeightNumber/String'500px'chart height
chartWidthNumber/String'100%'chart width
backgroundColorString'#fff'chart background color
offsetXNumber0chart offset X Axis
offsetYNumber0chart offset Y Axis
sparkLineBooleanfalseHelps to visualize data in small areas
titleString/Undefinedundefinedchart title
titleStyleObjectfontSize, fontWeight, color ...etcchart title style
dataLabelEnabledBooleantruechart label
dataLabelStringString''chart label suffix
dataLabelAnchorString'middle'chart label anchor position
dataLabelTextStyleObjectfontSize, fontWeight, color ...etcchart label style
dataLabelBackgroundArraytrue, '#fff', '#fff'used/unused, foreColor, borderColor
dataLabelTextShadowArrayfalse, '#000', 0.45enabled, color, opacity
chartLegendArraytrue, 'top', 'center', 0, 0show, position, horizontalAlign, offsetX, offsetY
chartMarkerArray0, 'circle'size, shape
chartNodataArrayundefined, 'middle', 0, 0, 14text, verticalAlign, offsetX, offsetY, fontSize
chartStrokeArraytrue, 'straight', 2, 0show, curve, width, dashArray
chartSubtitleArrayundefined, 'center', 0, 0, 12, '#9699a2'text, align, offsetX, offsetY, color
tooltipOptionsArraytrue, true, false, 'light', 12enabled, shared, fillSeriesColor, theme, fontSize
tooltipXAxisArraytrue, 'dd MMM'show, format
tooltipYAxisArray'', ''tooltip y axis suffix, tooltip y axis title suffix
XAxisOptionsArray'category', 'on', 'bottom', falsexAxis type, tickPlacement, position, tooltip enabled
YAxisOptionsArraytrue, false, false, 6, trueshow, opposite, reversed, tickAmount, labels show
colorSetArray'#008FFB', '#00E396', '#FEB019', '#FF4560', '#775DD0'color format
toolbarOptionsObjectshow, offsetX, offsetY, ... etc
zoomOptionsObjectenabled, type, autoScaleYaxis, ... etc

Chart PlotOptions Props

BarChart

PropTypeDefaultDescription
barHorizontalBooleanfalseBar chart type Horizontal or Vertical
barBorderRadiusNumber0Bar Border Radius
barColumnWidthString'70%'Bar width
barRangeColorArray0, 0, undefinedrange from, range to, color
barBackgroundStyleArray[[], 1, 0]['color',..., opacity, radius]
barDataLabelsArray'top', 'horizontal'data label position, data label orientation

AreaChart

PropTypeDefaultDescription
areaFillToString'origin''origin' or 'end' : When negative values are present in the area chart, fill the area

BubbleChart

PropTypeDefaultDescription
bubbleRadiusArrayundefined, undefinedminBubbleRadius, maxBubbleRadius

BoxPlotChart

PropTypeDefaultDescription
boxPlotColorsArray'#e9ecef', '#f8f9fa'upperColor, lowerColor

CandlestickChart

PropTypeDefaultDescription
candlestickColorArray'#e9ecef', '#f8f9fa'upwardColor, downwardColor
candlestickWickBooleantrueCandle wick color uses the same color as the body color

HeatmapChart

PropTypeDefaultDescription
heatmapRadiusNumber2heatmap square radius
heatmapReverseBooleantrueInvert Shading for Negative Numbers
heatmapStrokeBooleanfalseMake the heatmap border color the same as the cell color
heatmapColorScaleArray[]{from, to, color, foreColor, name},
heatmapInverseBooleanfalsevertically instead of horizontally

PieChart

PropTypeDefaultDescription
pieTypeString'pie'pie or donut
pieLabelsArray[]use in category
pieAnglesArray0, 360start and end angles of the pie
pieOnClickBooleanfalseextension when clicked
pieOffsetArray0, 0position coordinates of pie
pieLabelOffsetNumber0labels will move outside / inside of the donut area
pieShowLabelAngleNumber10Minimum angle to allow data-labels to show
donutBackgroundString'transparent'The background color of the pie
donutLabelsShowBooleanfalseWhether to display internal labels when donut
donutLabelValueSuffixString''The suffix on the label when donut
donutTotalShowBooleanfalseWhether to show the total value when donut
donutTotalStylesArray'Total', '22px', '#373d3f'total labels title, font size, font color

PolarAreaChart

PropTypeDefaultDescription
polarLabelsArray[]use in category
polarRingStrokeArray1, '#e8e8e8'Border width of the rings, The line/border color of the rings
polarSpokeStrokeArray1, '#e8e8e8'Border width of the spokes, The line/border color of the spokes

RadarChart

PropTypeDefaultDescription
radarOffsetArray0, 0offsetX, offsetY
radarStrokeArray'#e8e8e8', '#e8e8e8', 1radar stroke color, radar connector color, stroke width
radarFillColorArrayundefinedThe polygons can be filled with a custom color. 2 colors, the colors will be repeated for the rest of the polygons.

RadialBarChart

PropTypeDefaultDescription
radialBarLabelsArray[]use in category
radialBarInverseBooleanfalseWhether to make the first value of series innermost or outermost
radialBarAngleArray0, 360Angle from which the radialBars should start, end
radialBarOffsetArray0, 0Sets the offset for radialBars
radialBarHollowArray5, '50%', 'transparent'Spacing which will be subtracted from the available hollow size, Size in percentage relative to the total available size of chart, Background color for the hollow part
radialBarTrackArraytrue, undefined, undefinedShow track under the bar lines, track start angle, track end angle
radialBarTrackStyleArray'#f2f2f2', '97%', 1, 5track color, Width of the track, Opacity of the track, Spacing between each track
radialBarDataLabelsBooleantrueWhether to display labels inside radialBars
radialBarDataLabelsNameArraytrue, '16px', 600, undefined, -10Show the name of the respective bar associated with it’s value, font size, font weight, font color, Sets the top offset for name
radialBarDataLabelsValueArraytrue, '14px', 400, undefined, 16Show the value label associated with the name label, font size, font weight, font color, Sets the top offset for name
radialBarTotalArraytrue, 'Total', '#373d3f', '16px', 600Show the total of all the series in the inner area of radialBar, label name, label color, label size, label weight

TreeMapChart

PropTypeDefaultDescription
treeMapShadesBooleantrueEnables color shading based on value.
treeMapShadeIntensityNumber0.5intensity of shading
treeMapReverseBooleantrueWhen enabled, it will reverse the shades for negatives but keep the positive shades as it is now.
treeMapDistributeBooleanfalseWhen turned on, colors will be shaded for each series.
treeMapFillStrokeBooleanfalseWhen turned on, the stroke/border around the treemap cell has the same color as the cell color.
treeMapColorScaleArray{from: 0, to: 0, color: undefined, foreColor: undefined, }, ...{from: Value indicating range’s upper limit, to: Value indicating range’s lower limit, color: Background color to fill the range with, foreColor: Color of the text if data-labels is enabled}, ...
0.11.0

1 year ago

0.10.0

2 years ago

0.9.0

2 years ago

0.8.0

2 years ago

0.7.0

2 years ago

0.6.0

2 years ago

0.5.0

2 years ago

0.4.0

2 years ago

0.3.0

2 years ago

0.2.1

2 years ago

0.2.0

2 years ago

0.1.6

2 years ago

0.1.5

2 years ago

0.1.4

2 years ago

0.1.3

2 years ago

0.1.2

2 years ago

0.1.1

2 years ago

0.1.0

2 years ago