belloul
12th October 2017, 12:50
I need your help to find where is the problem why I can't see the curves, here is my code :
I think I need to refresh something, but don't know what, and what is weird is when I add new series to the graph that display a plot, if not I can't see the old one?
I put all my code for this part, because, I have some other small problems as, how to display an empty area with QChart and the best way to display points and the curve in same time, in an esthetic and fast way.
class chartClass(QChart):
def __init__(self, params):
super().__init__()
#init with params
self.allCruvs = []
self.allCruvs.append(QLineSeries(self))
self.addSeries(self.allCruvs[-1])
def plotData(self, Time, Values, color=None, curvIndex=0):
#test new curv or clear the old one
if (curvIndex < len(self.allCruvs)):
self.allCruvs[curvIndex].clear()
else:
curvIndex = len(self.allCruvs)
self.allCruvs.append(QLineSeries(self))
self.addSeries(self.allCruvs[-1])
# Get max and min for time axe and title
self.myZero = min(Time)
self.myMax = max(Time)
# define title
dateFormat = '%m/%d %H:%M'
myZeroSTR = datetime.datetime.fromtimestamp(int(self.myZero)). strftime(dateFormat)
myMaxSTR = datetime.datetime.fromtimestamp(int(self.myMax)).s trftime(dateFormat)
self.allCruvs[-1].setName(self.type + " [ " + myZeroSTR + " - " + myMaxSTR + " ]")
# define number of ticks // still in prehistoric way to do automatic new one
maxDelta = round(max(Time) - self.myZero, 0)
if (maxDelta < 20):
self.ticks = maxDelta + 1
elif maxDelta > 20:
self.ticks = int(maxDelta / 10) + 2
elif maxDelta > 200:
self.ticks = int(maxDelta / 100) + 2
elif maxDelta > 2000:
self.ticks = int(maxDelta / 1000) + 2
elif maxDelta > 20000:
self.ticks = int(maxDelta / 10000) + 2
# Set axis ticks and min/max
self.xAxe.setTickCount(self.ticks)
self.xAxe.setRange(0, maxDelta)
self.yAxe.setRange(min(Values), max(Values))
# set Pen and brush // need to plot line and the points with it
pen = QtGui.QPen()
brush = QtGui.QBrush()
pen.setWidthF(PENSIZE)
# pen.setWidthF(3)
pen.setCapStyle(Qt.RoundCap)
pen.setJoinStyle(Qt.RoundJoin)
# pen.setStyle(QtCore.Qt.NoPen)
# pen.setStyle(QtCore.Qt.SolidLine)
myColor = color
if color is None:
self.grColor += 1
self.grColor %= len(self.myPalette)
myColor = self.colorByIndex()
pen.setColor(myColor)
brush.setColor(myColor)
self.allCruvs[-1].setPointsVisible(True)
self.allCruvs[-1].setPen(pen)
pen.setBrush(brush)
self.allCruvs[-1].setBrush(brush)
lastTime = self.myZero
for i, theTime in enumerate(Time):
if (theTime > lastTime + MININTERVALTIME):
# Best thing to do is to plot an empty field, but couldn't do it so I plot an horizontal line for now
self.allCruvs[-1].append(lastTime - self.myZero, Values[i])
self.allCruvs[-1].append(theTime - self.myZero, Values[i])
lastTime = theTime
# when I add this part it plots the line but without points
try:
self.addSeries(self.allCruvs[-1])
# when I comment this part it does not plot the curv at all
#try:
# self.addSeries(self.allCruvs[-1])
# With this test I know that curvs exists and are in visible mode but nothing is shown on the screen
for curv in self.series():
print("self.allCruvs[] : ", len(curv), "is visible : ", curv.isVisible())
# curv.show() # do nothing new I can see
#self.show() # do nothing new I can see
Thanks in advance :D
I think I need to refresh something, but don't know what, and what is weird is when I add new series to the graph that display a plot, if not I can't see the old one?
I put all my code for this part, because, I have some other small problems as, how to display an empty area with QChart and the best way to display points and the curve in same time, in an esthetic and fast way.
class chartClass(QChart):
def __init__(self, params):
super().__init__()
#init with params
self.allCruvs = []
self.allCruvs.append(QLineSeries(self))
self.addSeries(self.allCruvs[-1])
def plotData(self, Time, Values, color=None, curvIndex=0):
#test new curv or clear the old one
if (curvIndex < len(self.allCruvs)):
self.allCruvs[curvIndex].clear()
else:
curvIndex = len(self.allCruvs)
self.allCruvs.append(QLineSeries(self))
self.addSeries(self.allCruvs[-1])
# Get max and min for time axe and title
self.myZero = min(Time)
self.myMax = max(Time)
# define title
dateFormat = '%m/%d %H:%M'
myZeroSTR = datetime.datetime.fromtimestamp(int(self.myZero)). strftime(dateFormat)
myMaxSTR = datetime.datetime.fromtimestamp(int(self.myMax)).s trftime(dateFormat)
self.allCruvs[-1].setName(self.type + " [ " + myZeroSTR + " - " + myMaxSTR + " ]")
# define number of ticks // still in prehistoric way to do automatic new one
maxDelta = round(max(Time) - self.myZero, 0)
if (maxDelta < 20):
self.ticks = maxDelta + 1
elif maxDelta > 20:
self.ticks = int(maxDelta / 10) + 2
elif maxDelta > 200:
self.ticks = int(maxDelta / 100) + 2
elif maxDelta > 2000:
self.ticks = int(maxDelta / 1000) + 2
elif maxDelta > 20000:
self.ticks = int(maxDelta / 10000) + 2
# Set axis ticks and min/max
self.xAxe.setTickCount(self.ticks)
self.xAxe.setRange(0, maxDelta)
self.yAxe.setRange(min(Values), max(Values))
# set Pen and brush // need to plot line and the points with it
pen = QtGui.QPen()
brush = QtGui.QBrush()
pen.setWidthF(PENSIZE)
# pen.setWidthF(3)
pen.setCapStyle(Qt.RoundCap)
pen.setJoinStyle(Qt.RoundJoin)
# pen.setStyle(QtCore.Qt.NoPen)
# pen.setStyle(QtCore.Qt.SolidLine)
myColor = color
if color is None:
self.grColor += 1
self.grColor %= len(self.myPalette)
myColor = self.colorByIndex()
pen.setColor(myColor)
brush.setColor(myColor)
self.allCruvs[-1].setPointsVisible(True)
self.allCruvs[-1].setPen(pen)
pen.setBrush(brush)
self.allCruvs[-1].setBrush(brush)
lastTime = self.myZero
for i, theTime in enumerate(Time):
if (theTime > lastTime + MININTERVALTIME):
# Best thing to do is to plot an empty field, but couldn't do it so I plot an horizontal line for now
self.allCruvs[-1].append(lastTime - self.myZero, Values[i])
self.allCruvs[-1].append(theTime - self.myZero, Values[i])
lastTime = theTime
# when I add this part it plots the line but without points
try:
self.addSeries(self.allCruvs[-1])
# when I comment this part it does not plot the curv at all
#try:
# self.addSeries(self.allCruvs[-1])
# With this test I know that curvs exists and are in visible mode but nothing is shown on the screen
for curv in self.series():
print("self.allCruvs[] : ", len(curv), "is visible : ", curv.isVisible())
# curv.show() # do nothing new I can see
#self.show() # do nothing new I can see
Thanks in advance :D