PolarChart2D Example
import sys, os
sys.path.append(os.path.dirname(os.path.realpath(__file__)) + "/../shared")
from DevMachines import __pyside2__, __pyside6__
from DevMachines.QtitanBase import Qtitan
from DevMachines.QtitanChart import (Chart, ChartPolarPointSeries2D, ChartPolarAreaSeries2D,
ChartPolarLineSeries2D, ChartPolarSplineSeries2D, ChartPolarSplineAreaSeries2D)
if __pyside2__:
from PySide2 import QtCore
from PySide2.QtCore import Qt
from PySide2.QtGui import QBrush, QIcon
from PySide2.QtWidgets import (QApplication, QComboBox)
if __pyside6__:
from PySide6 import QtCore
from PySide6.QtCore import Qt
from PySide6.QtGui import QBrush, QIcon
from PySide6.QtWidgets import (QApplication, QComboBox)
from DemoChartWindow import DemoChartWindow
class MainWindow(DemoChartWindow):
PolarPointSeries = 0
PolarLineSeries = 1
PolarAreaSeries = 2
PolarRadarSpline = 3
def __init__(self):
DemoChartWindow.__init__(self, "Polar Charts")
self.setChart(None)
self.createSeriesParametrs()
self.createPolarPointSeries()
self.createMarkersGroup()
# Option Labels
self.createLabelsGroup()
self.seriesChanged(self.seriesSwitcher.currentIndex())
self.updateValueParameters()
def createSeriesParametrs(self):
seriesTypeGroup = self.createGroupParameters(self.tr("Series"))
localLayout = seriesTypeGroup.layout()
self.seriesSwitcher = QComboBox(seriesTypeGroup)
self.seriesSwitcher.addItem("Polar Point", MainWindow.PolarPointSeries)
self.seriesSwitcher.addItem("Polar Line", MainWindow.PolarLineSeries)
self.seriesSwitcher.addItem("Polar Area", MainWindow.PolarAreaSeries)
self.seriesSwitcher.addItem("Polar Spline", MainWindow.PolarRadarSpline)
self.seriesSwitcher.setCurrentIndex(0)
self.connect(self.seriesSwitcher, QtCore.SIGNAL("currentIndexChanged(int)"), self,
QtCore.SLOT("seriesChanged(int)"))
localLayout.addRow(self.seriesSwitcher)
def createPolarPointSeries(self):
self.createTitle(self.tr("Polar Point"))
self.chart.legend().setVisible(True)
series = ChartPolarPointSeries2D()
series.setName(self.tr("Points 1"))
series.addXY(0.0 , 120.0)
series.addXY(30.0 , 110.0)
series.addXY(60.0 , 180.0)
series.addXY(90.0 , 145.0)
series.addXY(120.0, 145.0)
series.addXY(180.0, 100.0)
series.addXY(225.0, 190.0)
series.addXY(270.0, 120.0)
series.addXY(300.0, 130.0)
self.chart.appendSeries(series)
series = ChartPolarPointSeries2D()
series.setName(self.tr("Points 2"))
series.addXY(0.0 , 220.0)
series.addXY(30.0 , 80.0 )
series.addXY(60.0 , 100.0)
series.addXY(90.0 , 70.0 )
series.addXY(120.0, 20.0 )
series.addXY(150.0, 200.0)
series.addXY(180.0, 210.0)
series.addXY(210.0, 110.0)
series.addXY(270.0, 150.0)
series.addXY(300.0, 170.0)
series.addXY(330.0, 120.0)
self.chart.appendSeries(series)
def createPolarLineSeries(self):
self.createTitle(self.tr("Polar Line"))
self.chart.legend().setVisible(True)
series = ChartPolarLineSeries2D()
series.setName(self.tr("Line 1"))
for month in range(1, 13):
strMonth = QtCore.QLocale.system().monthName(month, QtCore.QLocale.ShortFormat)
series.addAxisPointY(50 + (QtCore.QRandomGenerator.global_().generate() % 50), strMonth)
self.chart.appendSeries(series)
def createPolarAreaSeries(self):
self.createTitle(self.tr("Polar Area"))
series = ChartPolarAreaSeries2D()
series.setName(self.tr("Area 1"))
for month in range(1, 13):
strMonth = QtCore.QLocale.system().monthName(month, QtCore.QLocale.ShortFormat)
series.addAxisPointY(50 + (QtCore.QRandomGenerator.global_().generate() % 50), strMonth)
self.chart.appendSeries(series)
def createPolarSplineSeries(self):
self.createTitle(self.tr("EM Field Strength(Polar)"))
series1 = ChartPolarSplineAreaSeries2D()
series1.setName(self.tr("Above 100MHz"))
series1.addXY(0, 5.5)
series1.addXY(30, 1.7)
series1.addXY(60, 5.0)
series1.addXY(90, 4.0)
series1.addXY(115, 9.0)
series1.addXY(120, 1.8)
series1.addXY(134, 9.5)
series1.addXY(150, 10.0)
series1.addXY(180, 9.7)
series1.addXY(210, 2.0)
series1.addXY(240, 3.9)
series1.addXY(254, 8.0)
series1.addXY(270, 9.0)
series1.addXY(300, 5.0)
series1.addXY(330, 6.0)
self.chart.appendSeries(series1)
series2 = ChartPolarSplineSeries2D()
series2.setName(self.tr("Below 100MHz"))
series2.addXY(0, 8.0)
series2.addXY(0.5, 6.0)
series2.addXY(1, 4.0)
series2.addXY(6, 2.6)
series2.addXY(30, 5.0)
series2.addXY(60, 5.4)
series2.addXY(75, 8.4)
series2.addXY(90, 9.0)
series2.addXY(115, 7.7)
series2.addXY(120, 8.6)
series2.addXY(150, 5.6)
series2.addXY(165, 7.6)
series2.addXY(180, 3.0)
series2.addXY(195, 9.0)
series2.addXY(210, 7.1)
series2.addXY(224, 8.9)
series2.addXY(234, 8.4)
series2.addXY(240, 8.1)
series2.addXY(255, 2.3)
series2.addXY(270, 5.0)
series2.addXY(285, 4.0)
series2.addXY(300, 1.6)
series2.addXY(315, 8.1)
series2.addXY(330, 8.4)
series2.addXY(340, 9.4)
series2.addXY(345, 9.2)
series2.addXY(0, 8.0)
self.chart.appendSeries(series2)
def updateValueParameters(self):
DemoChartWindow.updateValueParameters(self)
def seriesChanged(self, index):
self.chart.clearSeries()
self.chart.clearTitles()
self.chart.setBackgroundBrush(QBrush())
if index == MainWindow.PolarPointSeries:
self.createPolarPointSeries()
elif index == MainWindow.PolarLineSeries:
self.createPolarLineSeries()
elif index == MainWindow.PolarAreaSeries:
self.createPolarAreaSeries()
elif index == MainWindow.PolarRadarSpline:
self.createPolarSplineSeries()
self.updateValueParameters()
if __name__ == "__main__":
app = QApplication(sys.argv)
w = MainWindow()
w.show()
sys.exit(app.exec_())