コード例 #1
0
ファイル: piechart.py プロジェクト: Gayathrimenakath/PythonQt
    def create_donutchart(self, chartKey):
        series = QPieSeries()
        series.setHoleSize(0.35)

        for key, value in sample[chartKey].items():
            series.append(key, value)

        slice = QPieSlice()

        chart = QChart()
        #chart.legend().hide()
        chart.addSeries(series)

        # for the background and title
        chart.setAnimationOptions(QChart.SeriesAnimations)
        chart.setTitle("DonutChart Example")
        chart.setTheme(QChart.ChartThemeBlueCerulean)

        chartview = QChartView(chart)
        chartview.setRenderHint(QPainter.Antialiasing)

        # creating a widget object
        widget = QWidget()

        # Creating a grid layout
        layout = QGridLayout()

        # setting this layout to the widget
        widget.setLayout(layout)

        self.setCentralWidget(chartview)

        series.doubleClicked.connect(self.handle_double_clicked)
コード例 #2
0
class Chart(QWidget):
    def __init__(self, chartKey, data, frame, parent=None):
        super(Chart, self).__init__(parent)
        self.frame = frame
        self.data = data
        self.create_chart(chartKey)

    def create_chart(self, chartKey):
        self.series = QPieSeries()
        self.series.setHoleSize(0.35)
        self.chart = QChart()

        #Add series to the chart
        self.addSeries(chartKey)

        # for the background and title
        self.chart.setAnimationOptions(QChart.SeriesAnimations)
        self.chart.setTitle("Code Size Visualizer")
        self.chart.legend().setVisible(True)
        self.chart.legend().setAlignment(Qt.AlignRight)
        self.chart.setTheme(QChart.ChartThemeBlueCerulean)

        self.chartview = QChartView(self.chart)
        self.chartview.setRenderHint(QPainter.Antialiasing)

    #each section of the pie chart
    def addSeries(self, key):
        self.chart.removeAllSeries()
        self.series = QPieSeries()
        self.series.setHoleSize(0.35)

        #Show chartview only if the content length is less than 6. Otherwise show a table view
        if len(self.data[key]) < 6:
            #print('length',self.data, key)
            for key, value in self.data[key].items():
                print('key, value', key, value)
                slice_ = QPieSlice(str(key), value)
                self.series.append(slice_)

            self.series.setLabelsVisible()
            self.series.setLabelsPosition(QPieSlice.LabelInsideHorizontal)

            for slice in self.series.slices():
                #slice.setLabel(slice.label())
                slice.setLabel(slice.label() + ' - ' + str(slice.value()) +
                               ' B ')

            self.chart.addSeries(self.series)
            self.frame.frame.hide()
            self.chart.show()
        else:
            self.table = TableView(self.data[key], len(self.data[key]), 1)

            if self.frame.ly.count() > 0:
                self.frame.ly.itemAt(0).widget().setParent(None)

            self.frame.ly.addWidget(self.table)

            self.frame.frame.show()
            self.chart.hide()
コード例 #3
0
ファイル: anaxcel.py プロジェクト: jackSaluza/Anaxcel_PyQt5
 def analyseProcess(self):
     absc = []
     ordo = []
     absc.clear()
     ordo.clear()
     for tabrow in range(self.tableWidget.rowCount()):
         abscitem = self.tableWidget.item(tabrow,
                                          self.comboBoxabsc.currentIndex())
         ordoitem = self.tableWidget.item(tabrow,
                                          self.comboBoxordo.currentIndex())
         absc.append(int(abscitem.text()))
         ordo.append(str(ordoitem.text()))
     df = pd.DataFrame({'data': absc})
     df.index = ordo
     df = df.sort_values(by='data', ascending=False)
     df["cumpercentage"] = df["data"].cumsum() / df["data"].sum() * 100
     self.figure.clear()
     plt.ion()
     ax = self.figure.add_subplot()
     ax.bar(df.index, df["data"], color="C0")
     ax2 = ax.twinx()
     ax2.plot(df.index, df["cumpercentage"], color="C1", marker="D", ms=7)
     ax2.yaxis.set_major_formatter(PercentFormatter())
     ax.tick_params(axis="y", colors="C0")
     ax2.tick_params(axis="y", colors="C1")
     self.canvas.draw()
     # donutchart***********************************
     self.m_donuts = []
     self.chartView3.setRenderHint(QPainter.Antialiasing)
     self.chart3 = self.chartView3.chart()
     self.chart3.legend().setVisible(True)
     self.chart3.setTitle("Nested donuts Chart")
     self.chart3.setAnimationOptions(QChart.AllAnimations)
     minSize3 = 0.1
     maxSize3 = 0.9
     donutCount3 = 5
     for i in range(donutCount3):
         donut = QPieSeries()
         sliceCount = random.randrange(3, 6)
         # print(sliceCount)
         for j in range(sliceCount):
             value3 = random.randrange(0, 50)
             slice_ = QPieSlice(str(value3), value3)
             slice_.setLabelVisible(True)
             slice_.setLabelColor(Qt.white)
             slice_.setLabelPosition(QPieSlice.LabelInsideTangential)
             slice_.hovered[bool].connect(
                 functools.partial(self.explodeSlice, slice_=slice_))
             donut.append(slice_)
             donut.setHoleSize(minSize3 + i *
                               (maxSize3 - minSize3) / donutCount3)
             donut.setPieSize(minSize3 + (i + 1) *
                              (maxSize3 - minSize3) / donutCount3)
         self.m_donuts.append(donut)
         self.chartView3.chart().addSeries(donut)
     self.updateTimer = QTimer(self)
     self.updateTimer.timeout.connect(self.updateRotation)
     self.updateTimer.start(1250)
     self.tabWidget.setCurrentIndex(2)
コード例 #4
0
ファイル: mainMenu.py プロジェクト: zhongwenn1/Small-Project
    def createUnlinkedBar(self):
        pushed_bin = 0
        slipping_bin = 0
        others = 0
        try:
            total_bins = self.total_bins
            scanner_linked_rfid = self.scanner_linked_rfid
            unlinked_bins = total_bins - scanner_linked_rfid
            slipping_bin = len(self.slipping.index)
            pushed_bin = len(self.pushed.index)
            others = unlinked_bins-pushed_bin-slipping_bin

        except AttributeError:
            self.statusbar.showMessage('Data not ready')

        series = QPieSeries()
        series.setHoleSize(0.35)
        series.append("Pushed", pushed_bin)
        series.append("Slipping", slipping_bin)
        series.append("Others", others)
        slices = series.slices()[0]
        slices.setLabelVisible()
        slices.setLabel("{0} {1:.2f}".format("Pushed", 100*slices.percentage()))

        slices1 = series.slices()[1]
        slices1.setLabelVisible()
        slices1.setLabel("{0} {1:.2f}".format("Slipping", 100*slices1.percentage()))

        # set exploded slice
        if pushed_bin > slipping_bin:
            slices.setExploded()
        else:
            slices1.setExploded()

        slices2 = series.slices()[2]
        slices2.setLabelVisible()
        slices2.setLabel("{0} {1:.2f}".format("Others", 100*slices2.percentage()))

        chart = QChart()
        chart.setTheme(QChart.ChartThemeBlueCerulean)
        chart.legend().hide()
        font = QFont()
        font.setPixelSize(16)

        chart.setTitleFont(font)
        chart.setTitle("Unlinked Details")        
        chart.addSeries(series)
        chart.setAnimationOptions(QChart.SeriesAnimations)

        chartView = QChartView(chart)
        chartView.setRenderHint(QPainter.Antialiasing)

        return chartView
コード例 #5
0
class Chart(QWidget):
    def __init__(self, chartKey, parent=None):
        super(Chart, self).__init__(parent)
        self.create_chart(chartKey)
      
        
    def create_chart(self, chartKey):
        self.series = QPieSeries()
        self.series.setHoleSize(0.35)
        self.chart = QChart()
        
        #Add series to the chart
        self.addSeries(chartKey)

	# for the background and title
        self.chart.setAnimationOptions(QChart.SeriesAnimations)
        self.chart.setTitle("DonutChart Example")
        self.chart.setTheme(QChart.ChartThemeBlueCerulean)

        self.chartview = QChartView(self.chart)
        self.chartview.setRenderHint(QPainter.Antialiasing)
       
        
        
    def addSeries(self, key):
        self.chart.removeAllSeries()
        self.series = QPieSeries()
        self.series.setHoleSize(0.35)
            
        for key, value in sampleData[key].items():
            print("adding series", str(key), value)
            slice_ = QPieSlice(str(key), value)
            self.series.append(slice_)
       
        self.chart.addSeries(self.series)
        self.series.doubleClicked.connect(self.handle_double_clicked)
             
        
          
    #Show the update chart with the distribution of the selected slice
    def handle_double_clicked(self, slice):
        slice.setExploded()
        slice.setLabelVisible()
     
        if slice.label() in sampleData.keys():
            print("slice",slice.label());
            self.addSeries(slice.label())
コード例 #6
0
class Chart(QWidget):
    def __init__(self, chartKey, parent=None):
        super(Chart, self).__init__(parent)
        self.create_chart(chartKey, 0)
      
        
    def create_chart(self, chartKey, replace):
        self.series = QPieSeries()
        self.series.setHoleSize(0.35)
        self.chart = QChart()
        
        #Add series to the chart
        self.addSeries(chartKey)

	# for the background and title
        self.chart.setAnimationOptions(QChart.SeriesAnimations)
        self.chart.setTitle("DonutChart Example")
        self.chart.setTheme(QChart.ChartThemeBlueCerulean)

        self.chartview = QChartView(self.chart)
        self.chartview.setRenderHint(QPainter.Antialiasing)
       
        
        
    def addSeries(self, key):
        self.chart.removeAllSeries()
        self.series = QPieSeries()
        self.series.setHoleSize(0.35)
        print('chart',key)
            
        for key, value in sampleData[key].items():
            #print("adding series", str(key), value)
            slice_ = QPieSlice(str(key), value)
            self.series.append(slice_)
       
        self.chart.addSeries(self.series)
コード例 #7
0
class Chart(QtWidgets.QWidget):
    def __init__(self,chartKey, frame, parent=None):
        super(Chart, self).__init__(parent, QtCore.Qt.Window)  
        self.frame = frame
        self.create_chart(chartKey)
        
        
    @QtCore.pyqtSlot()
    def create_chart(self, chartKey):
        self.series = QPieSeries()
        self.series.setHoleSize(0.35)
        self.chart = QChart()
        
        print('inside chart',self.frame)
        
        #Add series to the chart
        self.addSeries(chartKey)

	# for the background and title
        self.chart.setAnimationOptions(QChart.SeriesAnimations)
        self.chart.setTitle("DonutChart Example")
        self.chart.setTheme(QChart.ChartThemeBlueCerulean)

        self.chartview = QChartView(self.chart)
        self.chartview.setRenderHint(QPainter.Antialiasing)
        
        
       
        
        
    def addSeries(self, key):
        self.chart.removeAllSeries()
        self.series = QPieSeries()
        print(self.series)
        self.series.setHoleSize(0.35)
        print('chart',key)
        
        if len(sampleData[key]) == 2:
            for key, value in sampleData[key].items():
                #print("adding series", str(key), value)
                slice_ = QPieSlice(str(key), value)
                self.series.append(slice_)
       
            self.chart.addSeries(self.series)
            #self.frame.frame.hide()
            
            #self.frame.frame.removeWidget(self.table)
            
            self.frame.frame.hide()
            self.chart.show()
        else:
            print('hi')
            
            self.table = TableView(data, 5, 4)
            
            
            if self.frame.ly.count() == 0:
                self.frame.ly.addWidget(self.table)
            
            self.frame.frame.show()
            self.chart.hide()
            #print(frame)
            print('parent', self.parent())
コード例 #8
0
class Chart(QWidget):
    def __init__(self, chartKey, data, frame, parent=None):
        super(Chart, self).__init__(parent)
        self.frame = frame
        self.data = data

        self.pt = self.parent()

        #add the to the main window
        #self.toolbar = QToolBar("Edit", self)
        #self.pt.addToolBar(self.toolbar)

        #ly = QtWidgets.QVBoxLayout()
        #self.frame = QtWidgets.QFrame()
        #self.frame.setLayout(ly)

        #self.layout = QtWidgets.QGridLayout()

        #print('----------------',self.frame)

        self.create_chart(chartKey)
        clicked = QtCore.pyqtSignal(QtCore.QModelIndex)
        #self.pt.addToolBar(self.navigationBar(data))

    def create_chart(self, chartKey):
        self.series = QPieSeries()
        self.series.setHoleSize(0.35)
        self.chart = QChart()

        #Add series to the chart
        self.addSeries(chartKey)

        # for the background and title
        self.chart.setAnimationOptions(QChart.SeriesAnimations)
        self.chart.setTitle("DonutChart Example")
        self.chart.setTheme(QChart.ChartThemeBlueCerulean)

        self.chartview = QChartView(self.chart)
        self.chartview.setRenderHint(QPainter.Antialiasing)

        #navigation = Navigation(classObj, self)
        #self.addToolBar(navigation.toolbar)

        #clicked = QtCore.pyqtSignal(QtCore.QModelIndex)

    def navigationBar(self, data):
        self.toolbar = QtWidgets.QToolBar()
        self.toolbar.actionTriggered.connect(self.on_actionTriggered)
        self.model = QtGui.QStandardItemModel(self)
        dict_to_model(self.model.invisibleRootItem(), data)
        it = self.model.item(0, 0)
        ix = self.model.indexFromItem(it)
        root_action = self.toolbar.addAction(it.text())
        root_action.setData(QtCore.QPersistentModelIndex(ix))
        self.listview = QtWidgets.QListView()
        self.listview.setEditTriggers(
            QtWidgets.QAbstractItemView.NoEditTriggers)
        #self.series.doubleClicked.connect(self.on_clicked)
        self.listview.setModel(self.model)
        self.listview.setRootIndex(ix)
        self.a = 10

        return self.toolbar

    #make the listed items clickable
    #@QtCore.pyqtSlot(QtCore.QModelIndex)
    def on_clicked(self, index):
        if not self.model.hasChildren(index):
            self.clicked.emit(index)
            return
        action = self.toolbar.addAction(index.data())
        action.setData(QtCore.QPersistentModelIndex(index))
        self.listview.setRootIndex(index)
        print(index.data())
        self.chart.addSeries(index.data())

    #make the breadcrumbs clickable in order to go back and forth
    #@QtCore.pyqtSlot(QtWidgets.QAction)
    def on_actionTriggered(self, action):
        ix = action.data()
        self.chart.addSeries(ix.data())
        model = ix.model()
        self.listview.setRootIndex(QtCore.QModelIndex(ix))
        self.toolbar.clear()
        ixs = []
        while ix.isValid():
            ixs.append(ix)
            ix = ix.parent()
        for ix in reversed(ixs):
            action = self.toolbar.addAction(ix.data())
            action.setData(ix)

    def addSeries(self, key):
        self.chart.removeAllSeries()
        self.series = QPieSeries()
        self.series.setHoleSize(0.35)

        #Show chartview only if the content length is less than 6. Otherwise show a table view
        if len(self.data[key]) < 6:
            for key, value in self.data[key].items():
                slice_ = QPieSlice(str(key), value)
                self.series.append(slice_)

            for slice in self.series.slices():
                slice.setLabel(slice.label())

            self.chart.addSeries(self.series)
            self.frame.frame.hide()
            self.chart.show()
        else:
            for m, item in self.data[key].items():
                print(m, item)

            self.table = TableView(self.data[key], len(self.data[key]), 1)

            if self.frame.ly.count() > 0:
                self.frame.ly.itemAt(0).widget().setParent(None)

            self.frame.ly.addWidget(self.table)

            self.frame.frame.show()
            self.chart.hide()

        self.series.doubleClicked.connect(self.handle_double_clicked)

    #Show the update chart with the distribution of the selected slice
    def handle_double_clicked(self, slice):
        slice.setExploded()
        slice.setLabelVisible()

        if slice.label() in self.data.keys():
            print("slice", slice.label())
            self.addSeries(slice.label())