change the candlestick data on click react js #1018
Replies: 4 comments
-
i need some help in this if anyone can help |
Beta Was this translation helpful? Give feedback.
-
Hi @zeeshan-shabbir, As you can see here, we are preparing a tutorial with React. Don't really know how you use/reuse your export const ChartComponent = props => {
const chartContainerRef = useRef();
useEffect(
() => {
const handleResize = () => {
chart.applyOptions({ width: chartContainerRef.current.clientWidth });
};
const { data } = props;
const chart = createChart(chartContainerRef.current, {
width: chartContainerRef.current.clientWidth,
height: chartContainerRef.current.clientHeight,
layout: {
backgroundColor: '#1c1f2d',
textColor: 'rgba(255, 255, 255, 0.9)',
},
grid: {
vertLines: {
color: '#334158',
},
horzLines: {
color: '#334158',
},
},
priceScale: {
borderColor: '#485c7b',
},
timeScale: {
borderColor: '#485c7b',
rightOffset: 2,
},
});
chart.timeScale().fitContent();
const newSeries = chart.addCandlestickSeries({
upColor: '#4bffb5',
downColor: '#ff4976',
borderDownColor: '#ff4976',
borderUpColor: '#4bffb5',
wickDownColor: '#838ca1',
wickUpColor: '#838ca1',
});
newSeries.setData(data);
window.addEventListener('resize', handleResize);
return () => {
window.removeEventListener('resize', handleResize);
chart.remove();
};
},
[props.data]
);
return (
<div
ref={chartContainerRef}
/>
);
}; |
Beta Was this translation helpful? Give feedback.
-
Using the above component with some random OHLC data it produces something like |
Beta Was this translation helpful? Give feedback.
-
Beta Was this translation helpful? Give feedback.
-
i am using react hook useffect to render my candlestick but when i want to change the data on click its does not change . when click i save my api data in use context hook and then use in my candlestick component .i dont how to change on click and didnt find any reference kindly help.
Beta Was this translation helpful? Give feedback.
All reactions