PyramidChart3D 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, ChartPyramidSeries3D, ChartPyramidSeriesLabel)
if __pyside2__:
from PySide2 import QtCore
from PySide2.QtCore import Qt
from PySide2.QtWidgets import (QApplication, QComboBox, QCheckBox, QSlider, QLabel)
if __pyside6__:
from PySide6 import QtCore
from PySide6.QtCore import Qt
from PySide6.QtWidgets import (QApplication, QComboBox, QCheckBox, QSlider, QLabel)
from DemoChartWindow import DemoChartWindow
class MainWindow(DemoChartWindow):
def __init__(self):
DemoChartWindow.__init__(self, "Pyramid Chart 3D")
self.setChart(Chart())
self.createSeriesParametrs()
self.createPyramidSeries()
self.updateValueParameters()
def createSeriesParametrs(self):
seriesTypeGroup = self.createGroupParameters(self.tr("Series"))
localLayout = seriesTypeGroup.layout()
self.circularSwitcher = QCheckBox(self.tr("Circular"), seriesTypeGroup)
self.connect(self.circularSwitcher, QtCore.SIGNAL("stateChanged(int)"), self, QtCore.SLOT("circularChanged(int)"))
localLayout.addRow(self.circularSwitcher)
self.transparency = QSlider(Qt.Horizontal, seriesTypeGroup)
self.transparency.setRange(0, 255)
self.transparency.setSliderPosition(255)
self.transparency.setSingleStep(5)
self.connect(self.transparency, QtCore.SIGNAL("valueChanged(int)"), self, QtCore.SLOT("transparencyChanged(int)"))
localLayout.addRow(QLabel(self.tr("Transparency:"), seriesTypeGroup))
localLayout.addRow(self.transparency)
self.gapSize = QSlider(Qt.Horizontal, seriesTypeGroup)
self.gapSize.setRange(0, 20)
self.gapSize.setSliderPosition(4)
self.gapSize.setSingleStep(1)
self.connect(self.gapSize, QtCore.SIGNAL("valueChanged(int)"), self, QtCore.SLOT("gapSizeChanged(int)"))
localLayout.addRow(QLabel(self.tr("Point Gap:"), seriesTypeGroup))
localLayout.addRow(self.gapSize)
self.rotation = QSlider(Qt.Horizontal, seriesTypeGroup)
self.rotation.setRange(-180, 180)
self.rotation.setSliderPosition(1)
self.rotation.setSingleStep(1)
self.connect(self.rotation, QtCore.SIGNAL("valueChanged(int)"), self, QtCore.SLOT("rotationChanged(int)"))
self.labelRotation = QLabel(self.tr("Rotation:"))
localLayout.addRow(self.labelRotation)
localLayout.addRow(self.rotation)
self.depthPercent = QSlider(Qt.Horizontal, seriesTypeGroup)
self.depthPercent.setRange(0, 45)
self.depthPercent.setSliderPosition(10)
self.depthPercent.setSingleStep(1)
self.connect(self.depthPercent, QtCore.SIGNAL("valueChanged(int)"), self, QtCore.SLOT("depthPercentChanged(int)"))
self.labeldepthPercen = QLabel(self.tr("Depth:"))
localLayout.addRow(self.labeldepthPercen)
localLayout.addRow(self.depthPercent)
# Option Labels
self.dataLabelsGroup = self.createGroupParameters(self.tr("Show Data Labels"), True)
localLayout = self.dataLabelsGroup.layout()
self.connect(self.dataLabelsGroup, QtCore.SIGNAL("toggled(bool)"), self, QtCore.SLOT("showDataLabels(bool)"))
self.angleDataLabelsSwitcher = QComboBox(self.dataLabelsGroup)
self.angleDataLabelsSwitcher.addItem("Left", ChartPyramidSeriesLabel.Left)
self.angleDataLabelsSwitcher.addItem("Right", ChartPyramidSeriesLabel.Right)
self.angleDataLabelsSwitcher.addItem("Center", ChartPyramidSeriesLabel.Center)
self.angleDataLabelsSwitcher.setCurrentIndex(1)
self.connect(self.angleDataLabelsSwitcher, QtCore.SIGNAL("currentIndexChanged(int)"), self, QtCore.SLOT("labelsPositionChanged(int)"))
# Layouts Labels
localLayout.addRow(self.tr("Position:"), self.angleDataLabelsSwitcher)
def createPyramidSeries(self):
self.createTitle(self.tr("Web Site Visitor Trend"))
self.chart.legend().setVisible(True)
series = ChartPyramidSeries3D()
pnt = series.add(9152, self.tr("Visited a Web Site: 9152"))
pnt.setLegendText(self.tr("Visited a Web Site: 100%"))
pnt = series.add(6870.0, self.tr("Downloaded a Trial: 6870"))
pnt.setLegendText(self.tr("Downloaded a Trial: 75%"))
pnt = series.add(5121.0, self.tr("Contacted to Support: 5121"))
pnt.setLegendText(self.tr("Contacted to Support: 56%"))
pnt = series.add(2224.0, self.tr("Subscribed: 2224"))
pnt.setLegendText(self.tr("Subscribed: 24%"))
pnt = series.add(1670.0, self.tr("Renewed: 1670"))
pnt.setLegendText(self.tr("Renewed: 18%"))
# series.setEqualHeight(True)
self.chart.appendSeries(series)
def updateValueParameters(self):
DemoChartWindow.updateValueParameters(self)
self.transparencyChanged(self.transparency.value())
self.gapSizeChanged(self.gapSize.value())
self.labelsPositionChanged(self.angleDataLabelsSwitcher.currentIndex())
self.depthPercentChanged(self.depthPercent.value())
self.rotationChanged(self.rotation.value())
def transparencyChanged(self, value):
listSeries = self.chart.series()
for series in listSeries:
series.setTransparency(value)
def gapSizeChanged(self, value):
listSeries = self.chart.series()
for series in listSeries:
series.setGapSize(value)
def rotationChanged(self, value):
listSeries = self.chart.series()
for series in listSeries:
series.setRotation(value)
def depthPercentChanged(self, value):
listSeries = self.chart.series()
for series in listSeries:
series.setDepthPercent(value)
def labelsPositionChanged(self, index):
v = self.angleDataLabelsSwitcher.itemData(index)
listSeries = self.chart.series()
for series in listSeries:
label = series.label()
label.setPosition(ChartPyramidSeriesLabel.Position(int(v)))
def circularChanged(self, check):
circular = check == Qt.Checked
listSeries = self.chart.series()
for series in listSeries:
series.setCircular(circular)
enabled = not circular
if circular:
self.depthPercent.setSliderPosition(10)
self.labeldepthPercen.setEnabled(enabled)
self.depthPercent.setEnabled(enabled)
self.labelRotation.setEnabled(enabled)
self.rotation.setEnabled(enabled)
if __name__ == "__main__":
app = QApplication(sys.argv)
w = MainWindow()
w.show()
sys.exit(app.exec_())