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
|
if (!candlestickSeriesRef.current || chartData.length === 0) return
|
||||||
|
|
||||||
const candleData: CandlestickData[] = chartData.map(d => ({
|
const candleData: CandlestickData[] = chartData.map(d => ({
|
||||||
time: (d.time / 1000) as Time,
|
time: (d.time / 1000) number,
|
||||||
open: d.open,
|
open: d.open,
|
||||||
high: d.high,
|
high: d.high,
|
||||||
low: d.low,
|
low: d.low,
|
||||||
@@ -195,7 +195,7 @@ export default function TradingChart() {
|
|||||||
// Volume
|
// Volume
|
||||||
if (volumeSeriesRef.current && chartData[0]?.volume) {
|
if (volumeSeriesRef.current && chartData[0]?.volume) {
|
||||||
const volumeData = chartData.map(d => ({
|
const volumeData = chartData.map(d => ({
|
||||||
time: (d.time / 1000) as Time,
|
time: (d.time / 1000) number,
|
||||||
value: d.volume || 0,
|
value: d.volume || 0,
|
||||||
color: d.close >= d.open ? 'rgba(34, 197, 94, 0.5)' : 'rgba(239, 68, 68, 0.5)',
|
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) {
|
if (ema20Ref.current) {
|
||||||
const closes = chartData.map(d => d.close)
|
const closes = chartData.map(d => d.close)
|
||||||
const ema20 = calculateEMA(closes, 20)
|
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 })
|
ema20Ref.current.applyOptions({ visible: true })
|
||||||
}
|
}
|
||||||
} else if (ema20Ref.current) {
|
} else if (ema20Ref.current) {
|
||||||
@@ -225,7 +225,7 @@ export default function TradingChart() {
|
|||||||
if (ema50Ref.current) {
|
if (ema50Ref.current) {
|
||||||
const closes = chartData.map(d => d.close)
|
const closes = chartData.map(d => d.close)
|
||||||
const ema50 = calculateEMA(closes, 50)
|
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 })
|
ema50Ref.current.applyOptions({ visible: true })
|
||||||
}
|
}
|
||||||
} else if (ema50Ref.current) {
|
} else if (ema50Ref.current) {
|
||||||
@@ -239,7 +239,7 @@ export default function TradingChart() {
|
|||||||
if (ema200Ref.current) {
|
if (ema200Ref.current) {
|
||||||
const closes = chartData.map(d => d.close)
|
const closes = chartData.map(d => d.close)
|
||||||
const ema200 = calculateEMA(closes, 200)
|
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 })
|
ema200Ref.current.applyOptions({ visible: true })
|
||||||
}
|
}
|
||||||
} else if (ema200Ref.current) {
|
} else if (ema200Ref.current) {
|
||||||
|
|||||||
Reference in New Issue
Block a user