Convert Figma logo to code with AI

rrag logoreact-stockcharts

Highly customizable stock charts with ReactJS and d3

3,867
957
3,867
137

Top Related Projects

📊 Interactive JavaScript Charts built on SVG

Performant financial charts built with HTML5 canvas

Highcharts JS, the JavaScript charting framework

16,856

Open-source JavaScript charting library behind Plotly and Dash

23,884

Redefined chart library built with React and D3

64,568

Simple HTML5 Charts using the <canvas> tag

Quick Overview

React-stockcharts is a charting library built with React and d3. It provides a set of customizable and interactive financial charts, including candlestick, line, and area charts. The library is designed to handle large datasets efficiently and offers various technical indicators and overlays.

Pros

  • Highly customizable with a wide range of chart types and technical indicators
  • Built with React, allowing for seamless integration with React applications
  • Supports large datasets with efficient rendering
  • Provides interactive features like zooming, panning, and tooltips

Cons

  • Limited documentation and examples, which can make it challenging for beginners
  • Not actively maintained, with the last update being several years ago
  • May require additional effort to integrate with modern React practices (e.g., hooks)
  • Performance issues reported by some users when dealing with very large datasets

Code Examples

  1. Creating a simple candlestick chart:
import { ChartCanvas, Chart } from "react-stockcharts";
import { CandlestickSeries } from "react-stockcharts/lib/series";
import { XAxis, YAxis } from "react-stockcharts/lib/axes";
import { utcDay } from "d3-time";

const CandlestickChart = ({ data, width, height }) => (
  <ChartCanvas
    width={width}
    height={height}
    data={data}
    xAccessor={(d) => d.date}
    xScale={utcDay}
  >
    <Chart id={1} yExtents={(d) => [d.high, d.low]}>
      <CandlestickSeries />
      <XAxis />
      <YAxis />
    </Chart>
  </ChartCanvas>
);
  1. Adding a moving average overlay:
import { LineSeries } from "react-stockcharts/lib/series";
import { MovingAverageTooltip } from "react-stockcharts/lib/tooltip";
import { ema } from "react-stockcharts/lib/indicator";

const MovingAverageChart = ({ data, width, height }) => {
  const ema20 = ema()
    .options({ windowSize: 20 })
    .accessor((d) => d.ema20)
    .stroke("blue");

  return (
    <ChartCanvas width={width} height={height} data={data}>
      <Chart id={1} yExtents={(d) => [d.high, d.low]}>
        <CandlestickSeries />
        <LineSeries yAccessor={ema20.accessor()} stroke={ema20.stroke()} />
        <MovingAverageTooltip
          origin={[8, 24]}
          options={[{ yAccessor: ema20.accessor(), type: "EMA", stroke: ema20.stroke(), windowSize: 20 }]}
        />
      </Chart>
    </ChartCanvas>
  );
};
  1. Implementing zooming and panning:
import { MouseCoordinateX, MouseCoordinateY } from "react-stockcharts/lib/coordinates";
import { ZoomButtons } from "react-stockcharts/lib/ZoomButtons";

const InteractiveChart = ({ data, width, height }) => (
  <ChartCanvas
    width={width}
    height={height}
    data={data}
    panEvent={true}
    zoomEvent={true}
  >
    <Chart id={1} yExtents={(d) => [d.high, d.low]}>
      <CandlestickSeries />
      <MouseCoordinateX />
      <MouseCoordinateY />
      <ZoomButtons />
    </Chart>
  </ChartCanvas>
);

Getting Started

  1. Install the package:

    npm install react-stockcharts
    
  2. Import required components:

    import { ChartCanvas, Chart } from "react-stockcharts";
    import { CandlestickSeries } from "react-stockcharts/lib/series";
    import { XAxis, YAxis }
    

Competitor Comparisons

📊 Interactive JavaScript Charts built on SVG

Pros of ApexCharts.js

  • More extensive documentation and examples
  • Wider range of chart types and customization options
  • Active development and frequent updates

Cons of ApexCharts.js

  • Larger file size and potentially slower performance
  • Less specialized for financial charts compared to react-stockcharts

Code Comparison

ApexCharts.js:

import ApexCharts from 'apexcharts'

const options = {
  chart: { type: 'candlestick' },
  series: [{ data: ohlcData }]
}

const chart = new ApexCharts(document.querySelector("#chart"), options)
chart.render()

react-stockcharts:

import { ChartCanvas, Chart } from "react-stockcharts"
import { CandlestickSeries } from "react-stockcharts/lib/series"

<ChartCanvas data={data} width={width} height={400}>
  <Chart id={1} yExtents={d => [d.high, d.low]}>
    <CandlestickSeries />
  </Chart>
</ChartCanvas>

ApexCharts.js offers a more straightforward API for creating charts, while react-stockcharts provides a more React-centric approach with greater control over individual chart components. ApexCharts.js is more versatile for various chart types, whereas react-stockcharts specializes in financial charts with advanced features for technical analysis.

Performant financial charts built with HTML5 canvas

Pros of lightweight-charts

  • More actively maintained with frequent updates
  • Lighter weight and faster performance
  • Better documentation and examples

Cons of lightweight-charts

  • Less customizable than react-stockcharts
  • Fewer chart types and technical indicators available
  • Steeper learning curve for React developers

Code Comparison

lightweight-charts:

const chart = createChart(document.body, { width: 400, height: 300 });
const lineSeries = chart.addLineSeries();
lineSeries.setData([
    { time: '2019-04-11', value: 80.01 },
    { time: '2019-04-12', value: 96.63 },
    { time: '2019-04-13', value: 76.64 },
]);

react-stockcharts:

<ChartCanvas width={400} height={300} data={data}>
    <Chart id={1} yExtents={d => d.close}>
        <LineSeries yAccessor={d => d.close} />
    </Chart>
</ChartCanvas>

lightweight-charts offers a more imperative API, while react-stockcharts provides a declarative React component-based approach. lightweight-charts is generally easier to set up and use for simple charts, but react-stockcharts offers more flexibility for complex, customized charts within React applications.

Highcharts JS, the JavaScript charting framework

Pros of Highcharts

  • More extensive documentation and examples
  • Wider range of chart types and customization options
  • Active development and regular updates

Cons of Highcharts

  • Commercial license required for most use cases
  • Steeper learning curve due to more complex API
  • Larger file size, potentially impacting page load times

Code Comparison

react-stockcharts:

import { ChartCanvas, Chart } from "react-stockcharts";
import { CandlestickSeries } from "react-stockcharts/lib/series";

<ChartCanvas data={data} width={800} height={400}>
  <Chart id={1} yExtents={d => [d.high, d.low]}>
    <CandlestickSeries />
  </Chart>
</ChartCanvas>

Highcharts:

Highcharts.chart('container', {
  series: [{
    type: 'candlestick',
    data: data
  }],
  yAxis: {
    title: { text: 'Price' }
  }
});

Both libraries offer ways to create stock charts, but Highcharts provides a more concise API for basic implementations. react-stockcharts requires more setup but offers greater flexibility for React-specific projects. Highcharts has a broader scope and can be used in various environments, while react-stockcharts is tailored for React applications.

16,856

Open-source JavaScript charting library behind Plotly and Dash

Pros of plotly.js

  • More comprehensive and versatile, supporting a wide range of chart types beyond financial charts
  • Active development with frequent updates and a large community
  • Extensive documentation and examples

Cons of plotly.js

  • Steeper learning curve due to its broader scope
  • Larger file size, which may impact load times for simpler projects

Code Comparison

plotly.js:

Plotly.newPlot('myDiv', [{
  x: [1, 2, 3, 4],
  y: [10, 15, 13, 17],
  type: 'scatter'
}]);

react-stockcharts:

<ChartCanvas width={width} height={400} ratio={ratio}>
  <Chart id={1} yExtents={d => [d.high, d.low]}>
    <CandlestickSeries />
  </Chart>
</ChartCanvas>

Summary

plotly.js is a more versatile and actively maintained library, suitable for various charting needs. It offers extensive documentation and community support but may be overkill for projects focused solely on stock charts. react-stockcharts is more specialized for financial charts, with a simpler API for stock-specific visualizations, but has less active development. The choice between the two depends on the specific requirements of your project and the desired balance between versatility and specialization.

23,884

Redefined chart library built with React and D3

Pros of Recharts

  • More active development and maintenance
  • Wider variety of chart types and customization options
  • Better documentation and examples

Cons of Recharts

  • Less specialized for financial/stock charts
  • May require more setup for complex financial visualizations

Code Comparison

React-stockcharts:

<ChartCanvas ratio={ratio} width={width} height={400}
  margin={{ left: 50, right: 50, top: 10, bottom: 30 }} type={type}
  seriesName="MSFT"
  data={data}
  xAccessor={d => d.date} xScaleProvider={discontinuousTimeScaleProvider}
  xExtents={[start, end]}>
  <Chart id={1} yExtents={d => [d.high, d.low]}>
    <CandlestickSeries />
  </Chart>
</ChartCanvas>

Recharts:

<ComposedChart width={600} height={400} data={data}>
  <XAxis dataKey="date" />
  <YAxis domain={['auto', 'auto']} />
  <Tooltip />
  <CandlestickSeries
    yAccessor={d => [d.open, d.high, d.low, d.close]}
    strokeWidth={1}
  />
</ComposedChart>

Both libraries offer React-based charting solutions, but React-stockcharts is more specialized for financial charts, while Recharts provides a broader range of chart types. Recharts has a more active community and better documentation, making it easier for beginners. However, for complex financial visualizations, React-stockcharts might offer more out-of-the-box functionality.

64,568

Simple HTML5 Charts using the <canvas> tag

Pros of Chart.js

  • More versatile and supports a wider range of chart types
  • Larger community and more frequent updates
  • Easier to set up and use for beginners

Cons of Chart.js

  • Less specialized for financial charts and stock data
  • May require more customization for advanced stock chart features

Code Comparison

Chart.js example:

new Chart(ctx, {
    type: 'line',
    data: {
        labels: ['Jan', 'Feb', 'Mar', 'Apr', 'May'],
        datasets: [{
            label: 'Stock Price',
            data: [10, 15, 7, 12, 9]
        }]
    }
});

react-stockcharts example:

<ChartCanvas ratio={ratio} width={width} height={400} margin={{ left: 50, right: 50, top: 10, bottom: 30 }} type="svg" seriesName="MSFT" data={data} xAccessor={d => d.date} xScaleProvider={discontinuousTimeScaleProvider}>
    <Chart id={1} yExtents={d => [d.high, d.low]}>
        <CandlestickSeries />
    </Chart>
</ChartCanvas>

Chart.js is a more general-purpose charting library, while react-stockcharts is specifically designed for financial charts. Chart.js offers simpler setup and a wider range of chart types, making it more accessible for various projects. However, react-stockcharts provides more specialized features for stock market data visualization out of the box, which may be preferable for finance-focused applications.

Convert Figma logo designs to code with AI

Visual Copilot

Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.

Try Visual Copilot

README

React Stockcharts

Join the chat at https://gitter.im/rrag/react-stockcharts npm version

Create highly customizable stock charts

Built with React JS and d3

If you like this project checkout gocharting.com

  • integrates multiple charttypes
  • over 60 technical indicators and overlays
  • drawing objects

Multiple quick start examples

  • svg and canvas for improved performance.
  • pan and zoom, on touch devices too

Chart types

  • Scatter
  • Area
  • Line
  • Candlestick
  • OHLC
  • HeikenAshi
  • Renko
  • Kagi
  • Point & Figure

Indicators

  • EMA, SMA, WMA, TMA
  • Bollinger band
  • SAR
  • MACD
  • RSI
  • ATR
  • Stochastic (fast, slow, full)
  • ForceIndex
  • ElderRay
  • Elder Impulse

(more to come),

and it is simple to create your own indicator too

Interactive Indicators

  • Trendline
  • Fibonacci Retracements
  • Gann Fan
  • Channel
  • Linear regression channel

Installation

npm install  --save react-stockcharts

Documentation

Documentation

Ready to use Examples

Contributing

Refer to CONTRIBUTING.md

Stability

This is alpha state software, the api will change with each minor version.

Roadmap

Roadmap

LICENSE

MIT

NPM DownloadsLast 30 Days