apexcharts / react-apexcharts

📊 React Component for ApexCharts
https://apexcharts.com
MIT License
1.3k stars 151 forks source link

React App hardly loads when loading large data sets into line chart #514

Open srichter98 opened 1 year ago

srichter98 commented 1 year ago

Hello, we are currently working on a module for our React app and want to integrate a line chart.

Our React app hardly loads when loading large data sets (example 100,000 - 300,000) and sometimes does not provide any feedback. Only leaving and reloading the page allows interacting with the app again.

We assume that this happens in connection with the chart.

Is there a way to load this big dataset? 

Following you'll find a code snipptet of our implementation:

function MachineCycleData(props) {
  const machineCycle = useSelector(selectMachineCycle);
  const [currentCycle, setCurrentCycle] = useState([]);
  const [time, setTime] = useState([]);

  const series = [
    {
      name: 'machine cycle',
      data: currentCycle,
    },
  ];
  let options = {
    chart: { id: 'machine-cycle', type: 'line' },
    stroke: {
      curve: 'stepline',
    },
    animations: {
      enabled: false,
    },
    xaxis: {
      type: 'datetime',
      categories: time,
      labels: {
        show: true,
        format: 'dd.MM.yy HH:mm:ss',
      },
      min: new Date('2023-02-27T09:00:00Z').getTime(), //Test
      max: new Date('2023-02-27T09:59:00Z').getTime(), //Test
    },
    tooltip: {
      theme: 'dark',
      x: {
        format: 'dd.MM.yy HH:mm:ss',
      },
    },
    legend: {
      position: 'top',
      fontSize: 14,
      offsetY: 0,
      markers: {
        width: 9,
        height: 9,
      },
    },
  };

 

  useEffect(() => {
    setCurrentCycle(
      machineCycle?.map((item) => (item.currentcycletime === null ? 0 : item.currentcycletime))
    );
    setTime(machineCycle?.map((item) => parseFloat(item.timestamp)));
  }, [machineCycle]);

 

  if (currentCycle.length == 0) {
    return null;
  }

 

  return (
<div className="w-full h-full flex flex-col">
<Chart options={options} series={series} height={'97%'} width={'100%'} />
</div>
  );
}
anitha-me commented 1 month ago

@srichter98, Did you found any solutions or work arounds ?

srichter98 commented 1 month ago

@anitha-me No we didn't find a solution or workaround, so we decided to use the npm package echarts-for-react which uses Apache ECharts.