示例#1
0
 def generatePicture(self):
     ## pre-computing a QPicture object allows paint() to run much more quickly,
     ## rather than re-drawing the shapes every time.
     self.picture = QtGui.QPicture()
     p = QtGui.QPainter(self.picture)
     p.setPen(pg.mkPen(color='w', width=0.4))  # 0.4 means w*2
     # w = (self.data[1][0] - self.data[0][0]) / 3.
     w = 0.2
     for (t, open, close, min, max) in self.data:
         p.drawLine(QtCore.QPointF(t, min), QtCore.QPointF(t, max))
         if open > close:
             p.setBrush(pg.mkBrush('g'))
         else:
             p.setBrush(pg.mkBrush('r'))
         p.drawRect(QtCore.QRectF(t-w, open, w*2, close-open))
     p.end()
示例#2
0
        def generatePicture(self):
            ## pre-computing a QPicture object allows paint() to run much more quickly,
            ## rather than re-drawing the shapes every time.
            self.picture = QtGui.QPicture()
            p = QtGui.QPainter(self.picture)
            p.setPen(pg.mkPen(color='w'))  # 0.4 means w*2, width=0.4
            w = 0.2  # w*2是 阴线阳线宽度

            # 用来记录上一个k线值 和打印更新的k线状态值
            global pre
            if len(self.data) == 0:
                pass
            elif len(self.data) < 2:
                pre = self.data[0]
                cur = self.data[0]
            else:
                cur = self.data[-1]
                if pre == cur:
                    pass
                else:
                    print cur
                    pre = cur

            for (t, open_price, close_price, min_price,
                 max_price) in self.data:
                '''
                这里对画最高最低值的竖直线的一种意外情况的判断,
                如果max和min一样,则画出来的直线实际上成了一个方块
                '''
                if abs(min_price - max_price) < 0.00000001:
                    pass  # 如果最高价和最低价相同,则不绘制这直线
                else:
                    p.drawLine(QtCore.QPointF(t, min_price),
                               QtCore.QPointF(t, max_price))
                if open_price > close_price:
                    p.setBrush(pg.mkBrush('g'))
                else:
                    p.setBrush(pg.mkBrush('r'))
                # 绘制open和close的柱状图
                p.drawRect(
                    QtCore.QRectF(t - w, open_price, w * 2,
                                  close_price - open_price))
            p.end()