Bar Series Not Allowing Drawings
Question
https://github.com/user-attachments/assets/9389a0b3-0f02-408b-8076-9face86b7305
Hello team,
I'm encountering an issue where using the addBarSeries method from the TradingView library seems to prevent any further drawings on the chart.
As demonstrated in the attached video, the chart initially allows drawings without any problems. However, immediately after the addBarSeries method is called in my code, the ability to add new drawings from the side bar is lost.
Could you please help me understand why this might be happening and how I can resolve this?
Code example
python
self.chart.switch_chart_type("bar")
self.chart.set(self.df, keep_drawings=True)
JS -> abstract
def switch_chart_type(self, type: str):
"""
Switches the chart type to either 'candle' or 'bar'.
"""
self.run_script(f"{self.id}.switchSeriesType('{type}')")
JS -> bundle.js
createSeries(chartType) {
if (chartType === "candle") {
return this.createCandlestickSeries();
} else if (chartType === "bar") {
return this.createBarSeries();
} else {
throw new Error("Invalid series type specified: " + this.seriesType);
}
}
createBarSeries() {
const settings = this.settings(); // Call settings method
// Fallback colors if settings or nested properties are missing
const defaultUpColor = "rgba(39, 157, 130, 100)";
const defaultDownColor = "rgba(200, 97, 100, 100)";
const t = settings?.chart?.candle_style?.up_color ?? defaultUpColor;
const e = settings?.chart?.candle_style?.down_color ?? defaultDownColor;
const i = this.chart.addBarSeries({
upColor: t,
borderUpColor: t,
wickUpColor: t,
downColor: e,
borderDownColor: e,
wickDownColor: e,
});
i.priceScale().applyOptions({
scaleMargins: {
top: 0.2,
bottom: 0.2,
},
});
return i;
}
I think the issue likely stems from an error in the way drawings are attached to the chart. Are you removing the main series when trying to add the bar series?
When the toolbox is created it requires a series that drawing primitives will be attached to. If the main series is removed the toolbox no longer has a valid series to attach drawing primitives too. Currently there isn't a way of specifying/modifying the series to use.
You could add an optional series parameter the the handler.createToolbox method to reinitialize it with a valid series, or instead of actually removing the main series just toggle the visibility instead.