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

    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.

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
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.