Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 9b36a1e

Browse files
authored
Update StockChart.tsx
1 parent 24f72a8 commit 9b36a1e

File tree

1 file changed

+31
-6
lines changed

1 file changed

+31
-6
lines changed

components/StockChart.tsx

Lines changed: 31 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ const StockChart: React.FC<StockChartProps> = ({ symbol, interval, range }) => {
109109
},
110110
timeScale: {
111111
timeVisible: true,
112-
rightOffset: 5,
112+
rightOffset: 10,
113113
minBarSpacing: 3,
114114
},
115115
width: chartContainerRef.current.clientWidth,
@@ -124,13 +124,14 @@ const StockChart: React.FC<StockChartProps> = ({ symbol, interval, range }) => {
124124

125125
chartRef.current = createChart(chartContainerRef.current, chartOptions)
126126

127-
// Candlestick
127+
// Candlestick series on main pane
128128
candlestickSeriesRef.current = chartRef.current.addBarSeries({
129129
upColor: '#089981',
130130
downColor: '#f23645',
131131
})
132132
candlestickSeriesRef.current.setData(data)
133-
// 10-period Moving Average
133+
134+
// 20-period Moving Average on main pane
134135
const maData = calculateMovingAverage(data, maLength)
135136
maSeriesRef.current = chartRef.current.addLineSeries({
136137
color: '#eab308', // yellow
@@ -139,6 +140,30 @@ const StockChart: React.FC<StockChartProps> = ({ symbol, interval, range }) => {
139140
})
140141
maSeriesRef.current.setData(maData)
141142

143+
// Volume series on separate pane at bottom
144+
volumeSeriesRef.current = chartRef.current.addHistogramSeries({
145+
color: theme === 'dark' ? '#4B5563' : '#9CA3AF',
146+
priceFormat: {
147+
type: 'volume',
148+
},
149+
priceScaleId: 'volume',
150+
scaleMargins: {
151+
top: 0.8,
152+
bottom: 0,
153+
},
154+
})
155+
156+
// Prepare volume data with color based on price movement
157+
const volumeData = data.map((item, index) => {
158+
const isUp = index > 0 ? item.close >= data[index - 1].close : true
159+
return {
160+
time: item.time,
161+
value: item.volume,
162+
color: isUp ? '#089981' : '#f23645'
163+
}
164+
})
165+
volumeSeriesRef.current.setData(volumeData)
166+
142167
chartRef.current.timeScale().fitContent()
143168

144169
if (data.length > 0) {
@@ -287,7 +312,7 @@ const StockCarousel: React.FC<StockCarouselProps> = ({
287312
{/* Single row layout for all controls */}
288313
<div className="bg-background border-muted-foreground/20">
289314
<div className="flex items-center justify-between gap-4">
290-
{/* Left side - Theme toggle and fullscreen */}
315+
{/* Left side - Theme toggle and fullscreen (hide fullscreen on small screens) */}
291316
<div className="flex items-center gap-2">
292317
<Button
293318
variant="outline"
@@ -301,9 +326,9 @@ const StockCarousel: React.FC<StockCarouselProps> = ({
301326
</div>
302327

303328
{/* Center - Category selector and interval buttons */}
304-
<div className="flex items-center gap-2">
329+
<div className="flex items-center gap-4">
305330
<select
306-
className="border border-muted-foreground/20 rounded px-1 py-1 text-xs bg-background"
331+
className="border border-muted-foreground/20 rounded px-2 py-1 text-xs bg-background"
307332
value={currentCategoryIndex}
308333
onChange={(e) => handleCategoryChange(Number(e.target.value))}
309334
>

0 commit comments

Comments
 (0)