Chart width is jumping on series change from area to candles
See original GitHub issueLightweight Charts Version: ^3.7.0
Actual behavior:
Width jumping on series change, see the next video:
Expected behavior:
No width jumping.
Steps/code to reproduce:
import React, { useCallback, useEffect, useReducer, useRef } from 'react'
import { useOnResize } from 'Core/utils/useOnResize'
import {
ChartOptions,
createChart,
DeepPartial,
IChartApi,
ISeriesApi,
SeriesType,
} from 'lightweight-charts'
import { useChartStyles } from './styles'
import { ChartCandlestickShape, ChartCommonShape, ChartType } from './types'
type Props = {
className?: string
data: Array<ChartCommonShape> | Array<ChartCandlestickShape>
options?: DeepPartial<ChartOptions>
type: ChartType
}
function ChartLocal(props: Props): JSX.Element {
const { className = '', data, options, type } = props
const [, forceUpdate] = useReducer((p: number) => p + 1, 0)
const chartStyles = useChartStyles()
const prevChartStyles = useRef(chartStyles)
const chartRef = useRef<HTMLDivElement | null>(null)
const chart = useRef<IChartApi>()
const series = useRef<ISeriesApi<SeriesType>>()
const handleResize = useCallback(() => {
if (chart.current && chartRef.current) {
chart.current?.resize(
chartRef.current.clientWidth,
chartRef.current.clientHeight,
true,
)
chart.current?.timeScale().fitContent()
}
}, [])
useOnResize(handleResize, 50)
useEffect(() => {
if (chartRef.current !== null) {
if (chart.current === undefined) {
chart.current = createChart(chartRef.current, {
height: chartRef.current.clientHeight,
width: chartRef.current.clientWidth,
...chartStyles.basic,
...options,
})
}
if (series.current) {
chart.current?.removeSeries(series.current)
}
if (type === 'Candlestick') {
series.current = chart.current?.addCandlestickSeries(chartStyles.candle)
} else {
series.current = chart.current?.addAreaSeries(chartStyles.area)
}
if (data) {
series.current?.setData(data)
}
chart.current?.timeScale().resetTimeScale()
chart.current?.timeScale().fitContent()
forceUpdate() // Update for tooltip
}
}, [chartRef.current, data, chartStyles])
return (
<div ref={chartRef} className={className}/>
)
}
export default ChartLocal
Issue Analytics
- State:
- Created 2 years ago
- Comments:6 (3 by maintainers)
Top Results From Across the Web
Charts candle width changes when adding another series
The point width for these candles is set using _stockSeries["PointWidth"] = "0.6"; I then add a new series to the same chart area...
Read more >Changing thickness of Bars and Candles without Zooming
Manipulating Bar and Candle Width This video demonstrates the process. Yes. Open your preference window for the chart (double-clicking in horizontal scale ...
Read more >My chart isn't locking/following the candles. How do I fix the ...
It's under settings, then time axis. There will be a option to add (or remove) a gap on the right side.
Read more >Candlestick Math - A New Way Of Using Candlesticks - YouTube
When two single candle lines are combined, the meaning on the chart can become much more significant. You'll get an even sharper view...
Read more >Changing bar / candle width independently of spacing
When changing candle spacing on the chart, MC automatically adjusts the bar or candle width so as to display them in such a...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
I can confirm this issue is fixed, thanks a lot, @timocov!
@iksent thanks! btw, if you add a new series first and then remove the old one it seems that it works fine. but this is quite strange for sure