Exemplo n.º 1
0
    def __iniChart(self):  #图表初始化
        self.chart = QPolarChart()  ##极坐标图
        self.chart.legend().setVisible(False)
        self.ui.chartView.setChart(self.chart)
        self.ui.chartView.setRenderHint(QPainter.Antialiasing)
        self.ui.chartView.setCursor(Qt.CrossCursor)

        self.__axisAngle = QValueAxis()  #角度坐标轴
        self.__axisAngle.setRange(0, 360)  #角度范围
        self.__axisAngle.setLabelFormat("NE %.0f")
        self.__axisAngle.setTickCount(9)
        self.chart.addAxis(self.__axisAngle,
                           QPolarChart.PolarOrientationAngular)

        self.__axisRadial = QValueAxis()  #径向坐标轴
        self.__axisRadial.setTickCount(6)
        self.__axisRadial.setLabelFormat("%.1f")  #标签格式
        self.chart.addAxis(self.__axisRadial,
                           QPolarChart.PolarOrientationRadial)

        pen = QPen(Qt.blue)
        pen.setWidth(2)
        seriesSpLine = QSplineSeries()
        seriesSpLine.setPen(pen)
        seriesSpLine.setPointsVisible(True)  #数据点可见
        seriesSpLine.hovered.connect(self.do_series_hovered)

        self.chart.addSeries(seriesSpLine)
        seriesSpLine.attachAxis(self.__axisAngle)
        seriesSpLine.attachAxis(self.__axisRadial)
Exemplo n.º 2
0
   def __createChart(self):  ##创建图表
      chart = QChart()  #创建 Chart
   ##      chart.setTitle("简单函数曲线")
      chart.legend().setVisible(True)
      self.chartView.setChart(chart)   #Chart添加到chartView

      pen=QPen()
      pen.setWidth(2)

   ##========LineSeries折线 和 ScatterSeries散点
      seriesLine = QLineSeries()
      seriesLine.setName("LineSeries折线")
      seriesLine.setPointsVisible(False)     #数据点不可见
      pen.setColor(Qt.red)
      seriesLine.setPen(pen)
      seriesLine.hovered.connect(self.do_series_hovered)    #信号 hovered
      seriesLine.clicked.connect(self.do_series_clicked)    #信号 clicked
      chart.addSeries(seriesLine)   #添加到chart

      seriesLinePoint = QScatterSeries()    #散点序列
      seriesLinePoint.setName("ScatterSeries散点")
      shape=QScatterSeries.MarkerShapeCircle  #MarkerShapeRectangle
      seriesLinePoint.setMarkerShape(shape)   #散点形状,只有2种
      seriesLinePoint.setBorderColor(Qt.yellow)
      seriesLinePoint.setBrush(QBrush(Qt.red))
      seriesLinePoint.setMarkerSize(10)      #散点大小
      seriesLinePoint.hovered.connect(self.do_series_hovered)  #信号 hovered
      seriesLinePoint.clicked.connect(self.do_series_clicked)  #信号 clicked
      chart.addSeries(seriesLinePoint)    #添加到chart

   ##======== SplineSeries 曲线和 QScatterSeries 散点
      seriesSpLine = QSplineSeries()
      seriesSpLine.setName("SplineSeries曲线")
      seriesSpLine.setPointsVisible(False)    #数据点不可见
      pen.setColor(Qt.blue)
      seriesSpLine.setPen(pen)
      seriesSpLine.hovered.connect(self.do_series_hovered)  #信号 hovered
      seriesSpLine.clicked.connect(self.do_series_clicked)  #信号 clicked


      seriesSpPoint = QScatterSeries()    #散点序列
      seriesSpPoint.setName("QScatterSeries")
      shape=QScatterSeries.MarkerShapeRectangle  #MarkerShapeCircle
      seriesSpPoint.setMarkerShape(shape) #散点形状,只有2种
      seriesSpPoint.setBorderColor(Qt.green)
      seriesSpPoint.setBrush(QBrush(Qt.blue))
      seriesSpPoint.setMarkerSize(10)     #散点大小
      seriesSpPoint.hovered.connect(self.do_series_hovered) #信号 hovered
      seriesSpPoint.clicked.connect(self.do_series_clicked) #信号 clicked

      chart.addSeries(seriesSpLine)
      chart.addSeries(seriesSpPoint)

   ##  创建缺省坐标轴
      chart.createDefaultAxes()  #创建缺省坐标轴并与序列关联
      chart.axisX().setTitleText("time(secs)")
      chart.axisX().setRange(0,10)
      chart.axisX().applyNiceNumbers()

      chart.axisY().setTitleText("value")
      chart.axisY().setRange(-2,2)
      chart.axisY().applyNiceNumbers()

      for marker in chart.legend().markers():  #QLegendMarker类型列表
         marker.clicked.connect(self.do_LegendMarkerClicked)