Skip to main content

Overview

This tutorial covers two approaches to building crypto candlestick charts with the Moralis OHLCV API:
  1. Chart.js — A popular, flexible charting library with a custom candlestick plugin
  2. TradingView Lightweight Charts — A professional-grade charting library built for financial data
Both approaches use React and fetch OHLCV data from the Moralis API.

Option 1: Building with Chart.js

Prerequisites

  • Node.js installed
  • Basic understanding of React
  • A Moralis API key (get one free)

Step 1: Project Setup

Create a new React project and install dependencies:
Create a .env file in your project root:

Step 2: Setup Chart.js Components

Create src/components/CandlestickChart.js:

Step 3: Create Custom Candlestick Plugin

Create src/plugins/candlestickPlugin.js:

Step 4: Update Chart Component with Plugin

Update your CandlestickChart to use the custom plugin:

Step 5: Implement Main App Component

Update App.js:

Step 6: Add Styling

Create src/styles.css:
Run with npm start.

Option 2: Building with TradingView Lightweight Charts

Step 1: Project Setup

Create a .env file:

Step 2: Create Components

ChainSelector (src/components/ChainSelector.js):
TokenInput (src/components/TokenInput.js):

Step 3: Implement the Chart Component

Create src/components/CandlestickChart.js:

Step 4: Implement Main App

Update App.js:

Step 5: Add Styling

Create src/styles.css:

Using the Application

  1. Select a blockchain network from the dropdown
  2. Enter a token address (e.g., USDT, WETH)
  3. Click “Fetch Pairs” to get available trading pairs
  4. Select a trading pair to view its price chart
  5. The chart will display OHLCV data for the last 30 days