def createPieChart(data):

    chart = QtCharts.QChart()
    # chart.legend().hide()
    chart.setTitle("Pie chart (refugees as of 2017)")

    series = QtCharts.QPieSeries()

    sliceList = list(
        map(lambda nv: QtCharts.QPieSlice(nv[0], nv[1]), zip(data[0],
                                                             data[1])))

    series.append(sliceList)

    for s in series.slices():
        s.setLabelVisible()

    chart = QtCharts.QChart()
    chart.addSeries(series)
    chart.setTitle("Simple piechart example")
    # chart.legend()->hide();

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

    return chartView
예제 #2
0
    def create_piechart(self):

        #Creates pie chart data.
        self.series = QtCharts.QPieSeries()
        self.series.append("DoS", 0)
        self.series.append("DDoS", 0)
        self.series.append("Benign", 0)
        self.series.append("SSH", 0)
        self.series.append("FTP", 0)

        #Adds slice.
        slice = QtCharts.QPieSlice()
        slice = self.series.slices()[2]
        slice.setExploded(True)
        slice.setLabelVisible(True)
        slice.setPen(QtGui.QPen(QtCore.Qt.darkGreen, 2))
        slice.setBrush(QtCore.Qt.green)

        #Create chart.
        self.chart = QtCharts.QChart()
        self.chart.legend().hide()
        self.chart.addSeries(self.series)
        self.chart.createDefaultAxes()
        self.chart.setTitle("Attacks Pie Chart")

        #Adds legend.
        self.chart.legend().setVisible(True)
        self.chart.legend().setAlignment(QtCore.Qt.AlignBottom)
        self.chart.setBackgroundVisible(False)

        #Render pie chart.
        chartview = QtCharts.QChartView(self.chart)
        chartview.setRenderHint(QtGui.QPainter.Antialiasing)

        return chartview
예제 #3
0
    def updatePieChart(self):

        #Remove data from pie chart.
        self.chart.removeSeries(self.series)

        #Creates new pie chart data -> series.
        self.series = QtCharts.QPieSeries()
        self.series.append("Benign", self.benignFlows)
        item = self.series.append("DoS", self.DoS)
        item.setBrush(QtGui.QColor("salmon"))
        item = self.series.append("DDoS", self.DDoS)
        item.setBrush(QtGui.QColor("blue"))
        item = self.series.append("SSH", self.SSH)
        item.setBrush(QtGui.QColor(0, 255, 255))
        item = self.series.append("FTP", self.FTP)
        item.setBrush(QtGui.QColor(255, 0, 255))

        #Adds slice.
        slice = QtCharts.QPieSlice()
        slice = self.series.slices()[0]
        slice.setExploded(True)
        slice.setLabelVisible(True)
        slice.setPen(QtGui.QPen(QtCore.Qt.darkGreen, 2))
        slice.setBrush(QtCore.Qt.green)

        #Adds data to pie chart.
        self.chart.addSeries(self.series)
예제 #4
0
    def refresh_probs_tab(self):
        self.probs_chart.removeAllSeries()

        if self.cell is not None:
            info = self.data_tools.get_probs_info_for_cell(
                self.cell)  #[(sym_label, prob), ...]
            series = QtCharts.QPieSeries()
            for (label, prob) in info:
                qslice = QtCharts.QPieSlice(label, prob)
                series.append(qslice)

            series.setLabelsVisible(True)
            self.probs_chart.addSeries(series)
예제 #5
0
    def creador_pieslice(self, valores, colores):
        '''theme 1: predeterminado, theme 2: personalizado'''

        lista_pieslice = []  # almacena QPieSlice
        for dato, color in zip(valores, colores):
            pieSlice = QtCharts.QPieSlice()
            pieSlice.setValue(dato)  # dato
            pieSlice.setColor(color)  # color leyenda
            pieSlice.setLabelColor("white")  # color valor

            # ubicacion de la señalizacion /-/-/-/
            'LabelOutside | LabelInsideHorizontal | LabelInsideTangential | LabelInsideNormal'
            pieSlice.setLabelPosition(QtCharts.QPieSlice.LabelOutside)

            lista_pieslice.append(pieSlice)

        return lista_pieslice
    def setup_donuts(self):
        for i in range(self.donut_count):
            donut = QtCharts.QPieSeries()
            slccount = randrange(3, 6)
            for j in range(slccount):
                value = randrange(100, 200)

                slc = QtCharts.QPieSlice(str(value), value)
                slc.setLabelVisible(True)
                slc.setLabelColor(Qt.white)
                slc.setLabelPosition(QtCharts.QPieSlice.LabelInsideTangential)

                # Connection using an extra parameter for the slot
                slc.hovered[bool].connect(partial(self.explode_slice, slc=slc))

                donut.append(slc)
                size = (self.max_size - self.min_size) / self.donut_count
                donut.setHoleSize(self.min_size + i * size)
                donut.setPieSize(self.min_size + (i + 1) * size)

            self.donuts.append(donut)
            self.chart_view.chart().addSeries(donut)
from PySide2.QtWidgets import (QApplication, QMainWindow)
from PySide2.QtCharts import QtCharts
import math

import ddv.csv


if __name__ == "__main__":

    app = QApplication(sys.argv)

    data = ddv.csv.getPieChartData("refugees-by-asylum.csv")
    
    series = QtCharts.QPieSeries()

    sliceList = list(map(lambda nv: QtCharts.QPieSlice(nv[0], nv[1]),
                         zip(data[0], data[1])))

    #s1 = QtCharts.QPieSlice("Jane", 1)
    # s2 = QtCharts.QPieSlice("Doe", 2)

    series.append(sliceList)
    #series.append("Jane", 1)
    #series.append("Joe", 2)
    #series.append("Andy", 3)
    #series.append("Barbara", 4)
    #series.append("Axel", 5)

    #slc = series.slices()[1]
    #slc.setExploded()
    #slc.setLabelVisible()
import numpy as np

import ddv.csv

if __name__ == "__main__":

    app = QApplication(sys.argv)
    df = pd.read_csv("refugees-by-asylum.csv")
    dfNumeric = df.select_dtypes(include=[np.number])

    # data = ddv.csv.getLineChartData("refugees-by-asylum.csv")

    series = QtCharts.QLineSeries()

    sliceList = list(
        map(lambda nv: QtCharts.QPieSlice(nv[0], nv[1]), zip(data[0],
                                                             data[1])))

    #s1 = QtCharts.QPieSlice("Jane", 1)
    # s2 = QtCharts.QPieSlice("Doe", 2)

    series.append(sliceList)
    #series.append("Jane", 1)
    #series.append("Joe", 2)
    #series.append("Andy", 3)
    #series.append("Barbara", 4)
    #series.append("Axel", 5)

    #slc = series.slices()[1]
    #slc.setExploded()
    #slc.setLabelVisible()