Graphs Scrolling Update, Issue

69 views
Skip to first unread message

Matty Kamp

unread,
May 15, 2023, 5:37:06 PM5/15/23
to pyqtgraph

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())



bug1.pngbug2.png

Matty Kamp

unread,
May 15, 2023, 5:47:40 PM5/15/23
to pyqtgraph

I added a workaround of removing and reapplying focus to the widget, and it resolved the issue. However, I'm not happy with this solution as it feels like a hack.

Reply all
Reply to author
Forward
0 new messages