備忘録

備忘録

EChartsを利用してグラフを描画する方法

Ⅰ. はじめに

タイトルの通り「EChartsを利用してグラフを描画する方法」です

Ⅱ. 手順

1. ECharts をインストールする
npm install echarts-for-react
2. サンプルコードを書く
import ReactECharts from 'echarts-for-react'

export default function App() {
  const options = {
    grid: { top: 8, right: 8, bottom: 24, left: 36 },
    xAxis: {
      type: 'category',
      data: ['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun'],
    },
    yAxis: {
      type: 'value',
    },
    series: [
      {
        data: [820, 932, 901, 934, 1290, 1330, 1320],
        type: 'line',
        smooth: true,
      },
    ],
    tooltip: {
      trigger: 'axis',
    },
  }

  return <ReactECharts option={options} />
}

実行結果