Created
May 18, 2025 22:39
-
-
Save leon-do/9f2e6721db5693deef7bb8e358c1165e to your computer and use it in GitHub Desktop.
TradingView Nextjs Example
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { useRef, useEffect } from 'react'; | |
import { CandlestickSeries, createChart } from 'lightweight-charts'; | |
export default function Chart() { | |
const chartContainerRef = useRef<HTMLDivElement>(null); | |
useEffect(() => { | |
const initialData = [ | |
{ time: '2018-12-22', open: 75.16, high: 82.84, low: 36.16, close: 45.72 }, | |
{ time: '2018-12-23', open: 45.12, high: 53.9, low: 45.12, close: 48.09 }, | |
{ time: '2018-12-24', open: 60.71, high: 60.71, low: 53.39, close: 59.29 }, | |
{ time: '2018-12-25', open: 68.26, high: 68.26, low: 59.04, close: 60.5 }, | |
{ time: '2018-12-26', open: 67.71, high: 105.85, low: 66.67, close: 91.04 }, | |
{ time: '2018-12-27', open: 91.04, high: 121.4, low: 82.7, close: 111.4 }, | |
{ time: '2018-12-28', open: 111.51, high: 142.83, low: 103.34, close: 131.25 }, | |
{ time: '2018-12-29', open: 131.33, high: 151.17, low: 77.68, close: 96.43 }, | |
{ time: '2018-12-30', open: 106.33, high: 110.2, low: 90.39, close: 98.1 }, | |
{ time: '2018-12-31', open: 109.87, high: 114.69, low: 85.66, close: 111.26 }, | |
]; | |
const chart = createChart(chartContainerRef.current!); | |
chart.timeScale().fitContent(); | |
const newSeries = chart.addSeries(CandlestickSeries, {}); | |
newSeries.setData(initialData); | |
}, []); | |
return <div ref={chartContainerRef} style={{ width: '100%', height: '500px' }} />; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment