Repository navigation
Adjusting the price scale #2093
|
Hello! |
Replies: 1 comment 2 replies
|
Thanks for the question! The title "Adjusting the price scale" is the right framing here. The price scale auto-scales by default — it fits the visible price range to whatever data is currently on screen. When you only have a few candlesticks (or just one), the scale tightly fits those bars, which is why they look "full-screen." As you accumulate history, more price variation appears and the scale relaxes. You can override this behaviour using the Fix a minimum price range so the scale never gets too tight: const series = chart.addSeries(CandlestickSeries, {
autoscaleInfoProvider: original => {
const res = original();
if (res !== null) {
// Ensure at least 10 price units of visible range
const mid = (res.priceRange.minValue + res.priceRange.maxValue) / 2;
const half = Math.max(
(res.priceRange.maxValue - res.priceRange.minValue) / 2,
5 // minimum half-range
);
res.priceRange.minValue = mid - half;
res.priceRange.maxValue = mid + half;
}
return res;
},
});Or if you know your instrument's expected price range up front, you can set it explicitly: const series = chart.addSeries(CandlestickSeries, {
autoscaleInfoProvider: () => ({
priceRange: {
minValue: 100,
maxValue: 200,
},
}),
});You can also add pixel-based margins above and below the auto-computed range without overriding it: autoscaleInfoProvider: original => {
const res = original();
if (res !== null) {
res.margins = { above: 20, below: 20 };
}
return res;
},For more context, these related issues discuss the same behaviour:
|

Thanks for the question! The title "Adjusting the price scale" is the right framing here.
The price scale auto-scales by default — it fits the visible price range to whatever data is currently on screen. When you only have a few candlesticks (or just one), the scale tightly fits those bars, which is why they look "full-screen." As you accumulate history, more price variation appears and the scale relaxes.
You can override this behaviour using the
autoscaleInfoProviderseries option. It lets you define a fixed price range, or expand the automatically-computed one by a margin.Fix a minimum price range so the scale never gets too tight: