+ Reply to Thread
Results 1 to 3 of 3

Thread: why QChart.addserie(curve) don't display dynamically when change occurs on curve?

  1. #1
    Join Date
    Oct 2017
    Posts
    3
    Qt products
    Platforms
    MacOS X Windows

    Talking why QChart.addserie(curve) don't display dynamically when change occurs on curve?

    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.

    Qt Code:
    1. class chartClass(QChart):[INDENT][INDENT]def __init__(self, params):
    2. super().__init__()
    3.  
    4. #init with params
    5.  
    6. self.allCruvs = []
    7. self.allCruvs.append(QLineSeries(self))
    8. self.addSeries(self.allCruvs[-1])
    9.  
    10.  
    11. def plotData(self, Time, Values, color=None, curvIndex=0):
    12.  
    13. #test new curv or clear the old one
    14. if (curvIndex < len(self.allCruvs)):
    15. self.allCruvs[curvIndex].clear()
    16. else:
    17. curvIndex = len(self.allCruvs)
    18. self.allCruvs.append(QLineSeries(self))
    19. self.addSeries(self.allCruvs[-1])
    20.  
    21. # Get max and min for time axe and title
    22. self.myZero = min(Time)
    23. self.myMax = max(Time)
    24.  
    25. # define title
    26. dateFormat = '%m/%d %H:%M'
    27. myZeroSTR = datetime.datetime.fromtimestamp(int(self.myZero)).strftime(dateFormat)
    28. myMaxSTR = datetime.datetime.fromtimestamp(int(self.myMax)).strftime(dateFormat)
    29. self.allCruvs[-1].setName(self.type + " [ " + myZeroSTR + " - " + myMaxSTR + " ]")
    30.  
    31. # define number of ticks // still in prehistoric way to do automatic new one
    32. maxDelta = round(max(Time) - self.myZero, 0)
    33. if (maxDelta < 20):
    34. self.ticks = maxDelta + 1
    35. elif maxDelta > 20:
    36. self.ticks = int(maxDelta / 10) + 2
    37. elif maxDelta > 200:
    38. self.ticks = int(maxDelta / 100) + 2
    39. elif maxDelta > 2000:
    40. self.ticks = int(maxDelta / 1000) + 2
    41. elif maxDelta > 20000:
    42. self.ticks = int(maxDelta / 10000) + 2
    43.  
    44. # Set axis ticks and min/max
    45. self.xAxe.setTickCount(self.ticks)
    46. self.xAxe.setRange(0, maxDelta)
    47. self.yAxe.setRange(min(Values), max(Values))
    48.  
    49. # set Pen and brush // need to plot line and the points with it
    50. pen = QtGui.QPen()
    51. brush = QtGui.QBrush()
    52.  
    53. pen.setWidthF(PENSIZE)
    54. # pen.setWidthF(3)
    55. pen.setCapStyle(Qt.RoundCap)
    56. pen.setJoinStyle(Qt.RoundJoin)
    57. # pen.setStyle(QtCore.Qt.NoPen)
    58. # pen.setStyle(QtCore.Qt.SolidLine)
    59.  
    60. myColor = color
    61. if color is None:
    62. self.grColor += 1
    63. self.grColor %= len(self.myPalette)
    64. myColor = self.colorByIndex()
    65.  
    66. pen.setColor(myColor)
    67. brush.setColor(myColor)
    68. self.allCruvs[-1].setPointsVisible(True)
    69.  
    70. self.allCruvs[-1].setPen(pen)
    71. pen.setBrush(brush)
    72. self.allCruvs[-1].setBrush(brush)
    73.  
    74. lastTime = self.myZero
    75. for i, theTime in enumerate(Time):
    76. if (theTime > lastTime + MININTERVALTIME):
    77. # Best thing to do is to plot an empty field, but couldn't do it so I plot an horizontal line for now
    78. self.allCruvs[-1].append(lastTime - self.myZero, Values[i])
    79.  
    80. self.allCruvs[-1].append(theTime - self.myZero, Values[i])
    81. lastTime = theTime
    82.  
    83.  
    84. # when I add this part it plots the line but without points
    85. try:
    86. self.addSeries(self.allCruvs[-1])
    87.  
    88. # when I comment this part it does not plot the curv at all
    89. #try:
    90. # self.addSeries(self.allCruvs[-1])
    91.  
    92. # With this test I know that curvs exists and are in visible mode but nothing is shown on the screen
    93. for curv in self.series():
    94. print("self.allCruvs[] : ", len(curv), "is visible : ", curv.isVisible())
    95.  
    96. # curv.show() # do nothing new I can see
    97.  
    98. #self.show() # do nothing new I can see[/INDENT][/INDENT]
    To copy to clipboard, switch view to plain text mode 

    Thanks in advance

  2. #2
    Join Date
    Oct 2017
    Posts
    3
    Qt products
    Platforms
    MacOS X Windows

    Default Re: why QChart.addserie(curve) don't display dynamically when change occurs on curve?

    Please any idea or help??

  3. #3
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    3,446
    Thanks
    203
    Thanked 535 Times in 525 Posts
    Qt products
    Qt5
    Platforms
    Unix/X11 Windows Android

    Default Re: why QChart.addserie(curve) don't display dynamically when change occurs on curve?

    There are no signals emitted from QAbstractSeries when the content of the series changes. So basically when you call addSeries(), the chart simply uses whatever data is there at the call, adds it to the plot, and then ignores any changes. QChart and QAbstractSeries are poorly-designed classes because they have no way for the series to tell the chart about changes, and no way for the chart to automatically update when a change is made to the series.

    QChart is derived from QGraphicsItem, so calling QGraphicsItem::update() might work.
    <=== The Great Pumpkin says ===>
    Please use CODE tags when posting source code so it is more readable. Click "Go Advanced" and then the "#" icon to insert the tags. Paste your code between them.

+ Reply to Thread

Similar Threads

  1. Replies: 1
    Last Post: 29th September 2013, 10:12
  2. Dynamically change existing curve color
    By missoni in forum Qwt
    Replies: 2
    Last Post: 19th June 2012, 12:32
  3. Replies: 4
    Last Post: 29th April 2010, 07:11
  4. Deleting points from a curve dynamically
    By maneesh18187 in forum Qwt
    Replies: 2
    Last Post: 9th February 2010, 19:08
  5. Replies: 1
    Last Post: 22nd January 2010, 15:34

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts