def create(self): ''' Creates Chart Data and returns ''' slices = QPieSlice() for x in range(0, len(self.chartseries.slices())): slices = self.chartseries.slices()[x] slices.setLabelVisible() slices.setLabel(str(slices.label()) + " : " + str(slices.value())) chart = QChart() chart.addSeries(self.chartseries) chart.setAnimationOptions(QChart.SeriesAnimations) chart.setTitle(self.title) # chart.setTheme(5) chart.legend().setVisible(False) chart.legend().attachToChart() return chart
def selectionChange(self): pilih_pantai = str(self.comboBox.currentText()) if pilih_pantai == '-Pilih-': self.ALL() return gf = Grafik(pilih_pantai) hasil = gf.hasil_grafik() hasil_dayatarik = hasil[0] hasil_aksesbilitas = hasil[1] hasil_kebersihan = hasil[2] hasil_fasilitas = hasil[3] total_pantai = hasil[4] daya_tarik = (hasil_dayatarik / total_pantai) * 100 aksesbilitas = (hasil_aksesbilitas / total_pantai) * 100 kebersihan = (hasil_kebersihan / total_pantai) * 100 fasilitas = (hasil_fasilitas / total_pantai) * 100 nilai = { 'Daya Tarik': daya_tarik, 'Aksesbilitas': aksesbilitas, 'Kebersihan': kebersihan, 'Fasilitas': fasilitas } maks = max(nilai['Daya Tarik'], nilai['Aksesbilitas'], nilai['Kebersihan'], nilai['Fasilitas']) for i in nilai: if maks == nilai[i]: print(i) set0 = QBarSet(pilih_pantai) set0 << daya_tarik << aksesbilitas << kebersihan << fasilitas series = QBarSeries() series.append(set0) series.setLabelsVisible(True) chart = QChart() chart.addSeries(series) chart.setTitle('Pantai ' + str(pilih_pantai)) labelnya = ["Daya Tarik", "Aksesbilitas", "Kebersihan", "Fasilitas"] series = QPieSeries() series.append("dt", daya_tarik) series.append("ak", aksesbilitas) series.append("keb", kebersihan) series.append("fas", fasilitas) slice = QPieSlice() slice = series.slices()[0] slice.setExploded(False) slice.setLabelVisible(True) slice.setBrush(QtGui.QColor("blue")) slice = QPieSlice() slice = series.slices()[1] slice.setExploded(False) slice.setLabelVisible(True) slice.setBrush(QtGui.QColor("red")) slice = QPieSlice() slice = series.slices()[2] slice.setExploded(False) slice.setLabelVisible(True) slice.setBrush(QtGui.QColor("green")) slice = QPieSlice() slice = series.slices()[3] slice.setExploded(False) slice.setLabelVisible(True) slice.setBrush(QtGui.QColor("orange")) i = 0 for slice in series.slices(): slice.setLabel(labelnya[i] + " {:.1f}%".format(100 * slice.percentage())) i = i + 1 chart = QChart() chart.legend().hide() chart.addSeries(series) chart.createDefaultAxes() chart.setAnimationOptions(QChart.SeriesAnimations) self.graphicsView.setChart(chart)