import React from 'react'
import ReactApexChart from 'react-apexcharts'
import './styles.css'

// The global window.Apex variable below can be used to set common options for all charts on the page
Apex = {
  chart: {
    height: 130,
  },
  title: {
    style: {
      fontSize: '14px',
    },
  },
  dataLabels: {
    enabled: false,
  },
  stroke: {
    curve: 'straight',
  },
  toolbar: {
    tools: {
      selection: false,
    },
  },
  markers: {
    size: 6,
    hover: {
      size: 10,
    },
  },
  tooltip: {
    followCursor: false,
    theme: 'dark',
    x: {
      show: false,
    },
    marker: {
      show: false,
    },
    y: {
      title: {
        formatter: function () {
          return ''
        },
      },
    },
  },
  grid: {
    clipMarkers: false,
  },
  yaxis: {
    tickAmount: 2,
  },
  xaxis: {
    type: 'datetime',
  },
}

// Deterministic daily random walks so every chart shares the same date range
// and the synced crosshair always has data under it.
function mulberry32(seed) {
  return function () {
    seed |= 0
    seed = (seed + 0x6d2b79f5) | 0
    var t = Math.imul(seed ^ (seed >>> 15), 1 | seed)
    t = (t + Math.imul(t ^ (t >>> 7), 61 | t)) ^ t
    return ((t ^ (t >>> 14)) >>> 0) / 4294967296
  }
}

function dailySeries(seed, count, base, spread) {
  var rand = mulberry32(seed)
  var series = []
  var ts = new Date('01 Jun 2025').getTime()
  var val = base
  for (var i = 0; i < count; i++) {
    val += (rand() - 0.5) * spread
    series.push([ts, Math.round(val)])
    ts += 86400000
  }
  return series
}

const ApexChart = () => {
  const [state, setState] = React.useState({
    series: [
      {
        name: 'Page Views',
        data: dailySeries(11, 20, 42, 18),
      },
    ],
    options: {
      chart: {
        id: 'pageviews',
        group: 'website',
        type: 'line',
        height: 130,
      },
      title: {
        text: 'Page Views (k)',
      },
      colors: ['#008FFB'],
    },
    seriesLine2: [
      {
        name: 'Sessions',
        data: dailySeries(23, 20, 20, 8),
      },
    ],
    optionsLine2: {
      chart: {
        id: 'sessions',
        group: 'website',
        type: 'line',
        height: 130,
      },
      title: {
        text: 'Sessions (k)',
      },
      colors: ['#546E7A'],
    },
    seriesArea: [
      {
        name: 'Sign-ups',
        data: dailySeries(35, 20, 38, 16),
      },
    ],
    optionsArea: {
      chart: {
        id: 'signups',
        group: 'website',
        type: 'area',
        height: 130,
      },
      title: {
        text: 'Sign-ups',
      },
      colors: ['#00E396'],
    },
  })

  return (
    <div>
      <div id="wrapper">
        <div id="chart-line">
          <ReactApexChart
            options={state.options}
            series={state.series}
            type="line"
            height={130}
          />
        </div>
        <div id="chart-line2">
          <ReactApexChart
            options={state.optionsLine2}
            series={state.seriesLine2}
            type="line"
            height={130}
          />
        </div>
        <div id="chart-area">
          <ReactApexChart
            options={state.optionsArea}
            series={state.seriesArea}
            type="area"
            height={130}
          />
        </div>
      </div>
    </div>
  )
}

export default ApexChart
Syncing Charts - React Line Charts | ApexCharts.js | ApexCharts.js