Hello everyone,
I'm trying to keep a candlestick chart updated in PyQtGraph, and everything
is going well. However, when I update the candlestick, it exhibits a bug
where the last candlestick retains parts that should be cleared or doesn't
draw the rectangle completely. Interestingly, if I hover my mouse over it,
the candlestick redraws correctly, or if I zoom in or out, it also fixes
the issue.
I'm wondering if anyone has any suggestions on how to address this? I
thought about triggering a range change every time I update the chart, but
it doesn't feel like the right approach. Additionally, if I change the
focus or switch to another window and come back, the issue is also resolved.
I would appreciate any insights or tips on how to resolve this bug. Thank
you in advance!
class CandleStick(pg.GraphicsObject):
def __init__(self, data):
pg.GraphicsObject.__init__(self)
self.data = data
self.generatePicture()
def generatePicture(self):
self.picture = QtGui.QPicture()
p = QtGui.QPainter(self.picture)
w = 0.33
for t, (open, close, min, max) in enumerate(self.data[['open', 'close',
'low', 'high']].to_numpy()):
t = t+1
if open > close:
p.setPen(pg.mkPen('r'))
p.drawLine(QtCore.QPointF(t, min), QtCore.QPointF(t, max))
p.setBrush(pg.mkBrush('r'))
p.drawRect(QtCore.QRectF(t-w, open, w*2, close-open))
elif open < close:
p.setPen(pg.mkPen('g'))
p.drawLine(QtCore.QPointF(t, min), QtCore.QPointF(t, max))
p.setBrush(pg.mkBrush('g'))
p.drawRect(QtCore.QRectF(t-w, open, w*2, close-open))
elif open == close:
if max == min:
p.setPen(pg.mkPen('g',width=1))
p.setBrush(pg.mkBrush('g'))
p.drawRect(QtCore.QRectF(t-w, open, w*2, 0))
else:
p.setPen(pg.mkPen('g'))
p.drawLine(QtCore.QPointF(t, min), QtCore.QPointF(t,max))
p.setBrush(pg.mkBrush('g'))
p.drawRect(QtCore.QRectF(t-w, open, w*2, 0))
p.end()
def update(self, data):
self.data = data
self.generatePicture()
def paint(self, p, *args):
p.drawPicture(0, 0, self.picture)
def boundingRect(self):
return QtCore.QRectF(self.picture.boundingRect())
[image: bug1.png][image: bug2.png]
--
You received this message because you are subscribed to the Google Groups
"pyqtgraph" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/pyqtgraph/e98c49e4-192c-49f9-b91b-09dd1e9ee6efn%40googlegroups.com.