Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

React examples #31

Open
Tenshinra opened this issue Aug 4, 2021 · 1 comment
Open

React examples #31

Tenshinra opened this issue Aug 4, 2021 · 1 comment

Comments

@Tenshinra
Copy link

Any plans to add some react examples for this lib? Would be very usefull :)

@karniv00l
Copy link

karniv00l commented Dec 14, 2021

Something like this is working good:

import { useEffect, useRef } from 'react';
import TimeChart from 'timechart';

const Chart = () => {
  const chartRef = useRef<HTMLDivElement | null>(null);

  useEffect(() => {
    const data = [];
    for (let x = 0; x < 100; x++) {
      data.push({ x, y: Math.random() });
    }

    const chart = new TimeChart(chartRef.current!, {
      series: [{ name: 'Random', data }],
      tooltip: true,
      zoom: {
        x: { autoRange: true },
        y: { autoRange: true },
      },
    });

    return () => chart.dispose();
  }, []);

  return (
    <div ref={chartRef} style={{ width: '100%', height: 500 }} />
  );
};

export default Chart;

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants