PyramidChart2D Example

import sys, os
sys.path.append(os.path.dirname(os.path.realpath(__file__)) + "/../shared")

from PySide2 import QtCore
from PySide2.QtCore import Qt, SIGNAL, SLOT, QDate, qrand
from PySide2.QtGui import QBrush, QIcon
from PySide2.QtWidgets import (QApplication, QComboBox, QSlider, QLabel)

from DevMachines.QtitanBase import Qtitan
from DevMachines.QtitanChart import (Chart, ChartPyramidSeries2D, ChartPyramidSeriesLabel)

from DemoChartWindow import DemoChartWindow

class MainWindow(DemoChartWindow):
    def __init__(self):
        DemoChartWindow.__init__(self, "Pyramid Chart 2D")
        self.setChart(Chart())
        self.createSeriesParametrs()
        self.createPyramidSeries()
        self.updateValueParameters()

    def createSeriesParametrs(self):
        seriesTypeGroup = self.createGroupParameters(self.tr("Series"))
        localLayout = seriesTypeGroup.layout()

        self.transparency = QSlider(Qt.Horizontal, seriesTypeGroup)
        self.transparency.setRange(0, 255)
        self.transparency.setSliderPosition(255)
        self.transparency.setSingleStep(5)
        self.connect(self.transparency, SIGNAL("valueChanged(int)"), self, 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, SIGNAL("valueChanged(int)"), self, SLOT("gapSizeChanged(int)"))
        localLayout.addRow(QLabel(self.tr("Point Gap:"), seriesTypeGroup))
        localLayout.addRow(self.gapSize)

        # Option Labels
        self.dataLabelsGroup = self.createGroupParameters(self.tr("Show Data Labels"), True)
        localLayout = self.dataLabelsGroup.layout()

        self.connect(self.dataLabelsGroup, SIGNAL("toggled(bool)"), self, 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, SIGNAL("currentIndexChanged(int)"), self, 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 = ChartPyramidSeries2D()

        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())

    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 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)))

if __name__ == "__main__":
    app = QApplication(sys.argv)
    w = MainWindow()
    w.show()
    sys.exit(app.exec_())