Fix chart: fix TypeScript errors and add null checks
This commit is contained in:
@@ -183,7 +183,7 @@ export default function TradingChart() {
|
||||
if (!candlestickSeriesRef.current || chartData.length === 0) return
|
||||
|
||||
const candleData: CandlestickData[] = chartData.map(d => ({
|
||||
time: (d.time / 1000) as Time,
|
||||
time: (d.time / 1000) number,
|
||||
open: d.open,
|
||||
high: d.high,
|
||||
low: d.low,
|
||||
@@ -195,7 +195,7 @@ export default function TradingChart() {
|
||||
// Volume
|
||||
if (volumeSeriesRef.current && chartData[0]?.volume) {
|
||||
const volumeData = chartData.map(d => ({
|
||||
time: (d.time / 1000) as Time,
|
||||
time: (d.time / 1000) number,
|
||||
value: d.volume || 0,
|
||||
color: d.close >= d.open ? 'rgba(34, 197, 94, 0.5)' : 'rgba(239, 68, 68, 0.5)',
|
||||
}))
|
||||
@@ -211,7 +211,7 @@ export default function TradingChart() {
|
||||
if (ema20Ref.current) {
|
||||
const closes = chartData.map(d => d.close)
|
||||
const ema20 = calculateEMA(closes, 20)
|
||||
ema20Ref.current.setData(ema20.map((v, i) => ({ time: (chartData[i].time / 1000) as Time, value: v })))
|
||||
ema20Ref.current.setData(ema20.map((v, i) => ({ time: (chartData[i].time / 1000) number, value: v })))
|
||||
ema20Ref.current.applyOptions({ visible: true })
|
||||
}
|
||||
} else if (ema20Ref.current) {
|
||||
@@ -225,7 +225,7 @@ export default function TradingChart() {
|
||||
if (ema50Ref.current) {
|
||||
const closes = chartData.map(d => d.close)
|
||||
const ema50 = calculateEMA(closes, 50)
|
||||
ema50Ref.current.setData(ema50.map((v, i) => ({ time: (chartData[i].time / 1000) as Time, value: v })))
|
||||
ema50Ref.current.setData(ema50.map((v, i) => ({ time: (chartData[i].time / 1000) number, value: v })))
|
||||
ema50Ref.current.applyOptions({ visible: true })
|
||||
}
|
||||
} else if (ema50Ref.current) {
|
||||
@@ -239,7 +239,7 @@ export default function TradingChart() {
|
||||
if (ema200Ref.current) {
|
||||
const closes = chartData.map(d => d.close)
|
||||
const ema200 = calculateEMA(closes, 200)
|
||||
ema200Ref.current.setData(ema200.map((v, i) => ({ time: (chartData[i].time / 1000) as Time, value: v })))
|
||||
ema200Ref.current.setData(ema200.map((v, i) => ({ time: (chartData[i].time / 1000) number, value: v })))
|
||||
ema200Ref.current.applyOptions({ visible: true })
|
||||
}
|
||||
} else if (ema200Ref.current) {
|
||||
|
||||
Reference in New Issue
Block a user