コード例 #1
0
    def create_barchart(self, series, max_val, animation=True):
        if animation:
            animation_type = QChart.AllAnimations
        else:
            animation_type = QChart.NoAnimation

        chart = QChart()
        chart.addSeries(series)
        chart.setBackgroundVisible(False)
        chart.setMargins(QMargins())
        chart.setAnimationOptions(animation_type)

        labels = ('Human', 'Bot')

        axisX = QBarCategoryAxis()
        axisX.append(labels)

        axisY = QValueAxis()
        axisY.setTitleText("Percentage (%)")
        axisY.setRange(0, max_val)

        chart.addAxis(axisX, Qt.AlignBottom)
        chart.addAxis(axisY, Qt.AlignLeft)

        font = QFont()
        font.setPointSize(9)

        chart.legend().setVisible(True)
        chart.legend().setFont(font)
        chart.legend().setAlignment(Qt.AlignBottom)

        self.ui.barchart.setChart(chart)
        self.ui.barchart.setRenderHint(QPainter.Antialiasing)
コード例 #2
0
ファイル: MessageCtrl.py プロジェクト: yrj2009yrj/RadarServer
class ChartWidget(QWidget):
    def __init__(self, number: int, parent=None):
        super(QWidget, self).__init__(parent)

        self.layout = QVBoxLayout(self)

        self.chart = QChart()
        self.chartView = QChartView(self.chart)
        self.chartView.setRenderHint(QPainter.Antialiasing)  # 抗锯齿
        self.layout.addWidget(self.chartView)

        self.channelNumber = number
        for index in range(self.channelNumber):
            tmp = QLineSeries()
            tmp.setName("channel "+str(index))
            self.chart.addSeries(tmp)

        self.chart.createDefaultAxes()
        self.chart.axisX().setRange(0, 25)
        self.chart.axisX().setTitleText("AAA")
        self.chart.axisY().setRange(0, 25)
        self.chart.axisY().setTitleText("BBB")

        # 标题
        self.chart.setTitle("XXX XXX XXX")
        # 指示颜色所代表的内容
        # self.chart.legend().hide()
        # 动画效果
        self.chart.setAnimationOptions(QChart.AllAnimations)

    def set_line(self, *lines):
        for index in range(len(lines)):
            self.chart.series()[index].clear()
            for v1, v2 in enumerate(lines[index]):
                self.chart.series()[index].append(v1, v2)
コード例 #3
0
    def create_linechart(self):

        series = QLineSeries(self)
        series.append(0, 6)
        series.append(2, 4)
        series.append(3, 8)
        series.append(7, 4)
        series.append(10, 5)

        series << QPointF(11, 1) << QPointF(13, 3) << QPointF(
            17, 6) << QPointF(18, 3) << QPointF(20, 2)

        chart = QChart()

        chart.addSeries(series)
        chart.createDefaultAxes()
        chart.setAnimationOptions(QChart.SeriesAnimations)
        chart.setTitle("Line Chart Example")

        chart.legend().setVisible(True)
        chart.legend().setAlignment(Qt.AlignBottom)

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

        self.setCentralWidget(chartview)
コード例 #4
0
    def __init__(self):
        super().__init__()

        series = QLineSeries()

        for date, value in DATA:
            date_value = QDateTime(*date, 0, 0).toMSecsSinceEpoch()
            series.append(date_value, value)

        chart = QChart()
        chart.setTheme(QChart.ChartThemeDark)
        chart.setTitle("Line Chart with Date Example")
        chart.setAnimationOptions(QChart.SeriesAnimations)
        chart.addSeries(series)
        chart.legend().hide()

        axisX = QDateTimeAxis()
        axisX.setFormat("dd/MM/yyyy")
        axisX.setTitleText('Date')
        chart.addAxis(axisX, Qt.AlignBottom)
        series.attachAxis(axisX)

        axisY = QValueAxis()
        axisY.setTitleText('Value')
        chart.addAxis(axisY, Qt.AlignLeft)
        series.attachAxis(axisY)

        chart_view = QChartView()
        chart_view.setChart(chart)
        chart_view.setRenderHint(QPainter.Antialiasing)

        self.setCentralWidget(chart_view)
    def __init__(self):
        super().__init__()

        series = QLineSeries()
        series.setPointsVisible(True)
        series.setPointLabelsVisible(True)
        series.setPointLabelsFormat("(@xPoint, @yPoint)")
        series.append(0, 6)
        series.append(2, 4)
        series.append(3, 8)
        series.append(7, 4)
        series.append(10, 5)

        chart = QChart()
        chart.setTitle("Line Chart Example")
        chart.setAnimationOptions(QChart.SeriesAnimations)
        chart.legend().hide()
        chart.addSeries(series)
        chart.createDefaultAxes()

        chart_view = QChartView()
        chart_view.setChart(chart)
        chart_view.setRenderHint(QPainter.Antialiasing)

        self.setCentralWidget(chart_view)
コード例 #6
0
    def unlinkedChartDist(self, data):
        chart = QChart()
        chart.setAnimationOptions(QChart.SeriesAnimations)
        self.getCertainRangeList(data)

        chartView = QChartView(chart)
        return chartView
コード例 #7
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()
class MainWindow(ChartViewToolTips):
    def __init__(self):
        super().__init__()

        series = QLineSeries()
        series.setPointsVisible(True)
        series.setPointLabelsVisible(True)
        series.setPointLabelsFormat("(@xPoint, @yPoint)")
        series.hovered.connect(self.show_series_tooltip)

        series.append(0, 6)
        series.append(2, 4)
        series.append(3, 8)
        series.append(7, 4)
        series.append(10, 5)

        self._chart = QChart()
        self._chart.setMinimumSize(640, 480)
        self._chart.setTitle("Line Chart Example")
        self._chart.setAnimationOptions(QChart.SeriesAnimations)
        self._chart.legend().hide()
        self._chart.addSeries(series)
        self._chart.createDefaultAxes()

        self.setChart(self._chart)
コード例 #9
0
    def bargraph(self):
        '''
        Processes and Creates Bar Graph.
        '''
        self.barchart = self.findChild(QChartView, "attackgraph")
        bardata = self.data.getBar()
        chartobj = Barchart(bardata)
        chartseries = chartobj.getSeries()

        # create QChart object and add data
        chart = QChart()
        chart.addSeries(chartseries)
        chart.setTitle("Attacks Over the Past 12 Months")
        chart.setAnimationOptions(QChart.SeriesAnimations)

        axisX = QBarCategoryAxis()
        axisX.append(chartobj.getKeys())
        chart.addAxis(axisX, Qt.AlignBottom)

        axisY = QValueAxis()
        axisY.setRange(0, chartobj.getMax())
        chart.addAxis(axisY, Qt.AlignLeft)

        chart.legend().setVisible(False)

        self.barchart.setChart(chart)
コード例 #10
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)
コード例 #11
0
    def show_diagram(self):
        self.student_diagram_ui.label_4.setText(self.label_2.text())
        self.student_diagram_ui.label_7.setText(self.label_8.text())
        self.student_diagram_ui.label_8.setText(self.label_6.text())
        self.student_diagram_ui.label_10.setText(self.label_4.text())

        max_value = 0
        series = QBarSeries()
        for i in self.result:
            set0 = QBarSet(i[0])
            set0.append(float(i[1]))
            series.append(set0)
            if max_value < (float(i[1])):
                max_value = float(i[1])

        axisY = QValueAxis()
        axisY.setRange(0, max_value)

        chart = QChart()
        series.attachAxis(axisY)
        chart.addSeries(series)
        chart.setAnimationOptions(QChart.SeriesAnimations)

        chart.addAxis(axisY, Qt.AlignLeft)
        chart.legend().setVisible(True)
        chart.legend().setAlignment(Qt.AlignBottom)
        centralwidget = self.student_diagram_ui.centralwidget
        self.student_diagram_ui.chartview = QChartView(chart, centralwidget)
        self.student_diagram_ui.chartview.setGeometry(QtCore.QRect(10, 110, 880, 371))
        self.student_diagram_ui.pushButton_3.show()
        self.student_diagram_ui.update(self.dark_theme)
        self.student_diagram_window.show()
コード例 #12
0
    def __init__(self, *args, **kwargs):
        super(Window, self).__init__(*args, **kwargs)
        self.resize(400, 300)
        # 抗锯齿
        self.setRenderHint(QPainter.Antialiasing)

        # 图表
        chart = QChart()
        self.setChart(chart)
        # 设置标题
        chart.setTitle('Simple barchart example')
        # 开启动画效果
        chart.setAnimationOptions(QChart.SeriesAnimations)
        # 添加Series
        series = self.getSeries()
        chart.addSeries(series)
        # 分类
        categories = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun']
        # 分类x轴
        axis = QBarCategoryAxis()
        axis.append(categories)
        # 创建默认轴线
        chart.createDefaultAxes()
        # 替换默认x轴
        chart.setAxisX(axis, series)
        # 显示图例
        chart.legend().setVisible(True)
        chart.legend().setAlignment(Qt.AlignBottom)
コード例 #13
0
    def make_bar_chart(self):
        chart = QChart()

        chart.setTitle("현재 재고 현황")
        chart.setAnimationOptions(QChart.SeriesAnimations)

        item_statistics_dict = self.statistics_manager.get_item_statistics_dict(
        )
        categories = ["2020년"]

        series = QBarSeries()
        for key, value in item_statistics_dict.items():
            set = QBarSet(key)
            set << value[REMAIN_COUNT]
            series.append(set)

        chart.addSeries(series)

        axis = QBarCategoryAxis()
        axis.append(categories)
        chart.createDefaultAxes()
        chart.setAxisX(axis, series)

        chart.legend().setVisible(True)
        chart.legend().setAlignment(Qt.AlignBottom)

        self.barChartView = QChartView(chart)
        self.barChartView.setRenderHint(QPainter.Antialiasing)
        self.statisticsWidget.setWidget(self.barChartView)
コード例 #14
0
    def create_piechart(self, series, animation=True):
        if animation:
            animation_type = QChart.AllAnimations
        else:
            animation_type = QChart.NoAnimation

        font_title = QFont()
        font_title.setBold(True)
        font_title.setPointSize(13)

        # define the chart properties
        chart = QChart()
        chart.addSeries(series)
        chart.createDefaultAxes()
        chart.setAnimationOptions(animation_type)
        chart.setBackgroundVisible(False)
        chart.setMargins(QMargins())
        chart.setTitle("Prediction Distribution")
        chart.setTitleFont(font_title)

        font_legend = QFont()
        font_legend.setBold(True)

        # define legend properties
        chart.legend().show()
        chart.legend().setVisible(True)
        chart.legend().setAlignment(Qt.AlignBottom)
        chart.legend().setFont(font_legend)
        self.ui.piechart.setChart(chart)
        self.ui.piechart.setRenderHint(QPainter.Antialiasing)
        QApplication.processEvents()
コード例 #15
0
    def __init__(self, predictions, probabilities):
        # calls the parent (QMainWindow) constructor
        super().__init__()

        # Size of the window
        self.resize(800, 600)

        # The title of the window
        self.setWindowTitle("Flower Confidence score graph")

        # The array to hold flower sets
        self.flowerSets = []

        # A Q bar series object
        self.flowerSeries = QBarSeries()

        # The for loop add Q bar sets and probabilities to the Q bsr series object.
        for i in range(5):
            self.flowerSets.append(
                QBarSet(predictions[i] +
                        " ({0:.3f}%)".format(probabilities[i])))
            self.flowerSets[i].append(probabilities[i])
            self.flowerSeries.append(self.flowerSets[i])

        # creates the char that will be the bar graph chart (also the base class of all qt charts)
        flowerChart = QChart()

        # added the series object to the chart object
        flowerChart.addSeries(self.flowerSeries)

        # Adds a title to the graph
        flowerChart.setTitle('Confidence score percentages by flower type')

        # Gives the graph a nice animation when opened
        flowerChart.setAnimationOptions(QChart.SeriesAnimations)

        # The next two line label the x axis
        axisX = QBarCategoryAxis()
        axisX.append(["Flower Types"])

        # Gives the y axis its values
        axisY = QValueAxis()
        axisY.setRange(0, probabilities[0])

        # added the axises to the chart
        flowerChart.addAxis(axisX, Qt.AlignBottom)
        flowerChart.addAxis(axisY, Qt.AlignLeft)

        # Makes sure teh legend is visible
        flowerChart.legend().setVisible(True)

        # Places the  legend to the bottom of the chart
        flowerChart.legend().setAlignment(Qt.AlignBottom)

        # places the chart in a chart view
        flowerChartView = QChartView(flowerChart)

        # Adds the chart to the main widget
        self.setCentralWidget(flowerChartView)
    def build(self):
        self.setWindowTitle("Histogram - " + self.name)
        self.setMinimumSize(400, 300)

        # Close when ctrl+w is triggered
        QShortcut(QKeySequence("Ctrl+W"), self, self.close)

        # 2D array -> 1D array
        img = self.image.ravel()

        # Process histogram
        histogram, bin_edges = np.histogram(img, bins='auto')

        bar_series = QBarSeries()
        bar_ = QBarSet("")

        # Append values
        for val in histogram:
            bar_.append(val)

        pen = bar_.pen()
        pen.setColor(Qt.black)
        pen.setWidth(0.1)
        bar_.setPen(pen)

        # Append bar to the bar series
        bar_series.append(bar_)

        # Chart object
        chart = QChart()
        chart.addSeries(bar_series)

        # Active animation
        chart.setAnimationOptions(QChart.SeriesAnimations)

        # Do not show title
        chart.legend().setVisible(False)

        # Draw Axes, with [min, max]
        # Y axis
        h_max = histogram.max()
        axis_y = QValueAxis()
        axis_y.setRange(0, h_max)

        # X axis
        be_max = bin_edges.max()
        be_min = bin_edges.min()
        axis_x = QValueAxis()
        axis_x.setRange(be_min, be_max)

        # Add axis to chart + rendering
        chart.addAxis(axis_x, Qt.AlignBottom)
        chart.addAxis(axis_y, Qt.AlignLeft)

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

        self.setCentralWidget(view)
コード例 #17
0
ファイル: mainMenu.py プロジェクト: zhongwenn1/Small-Project
    def createBar(self):
        min_num, max_num = 0, 100
        linked_bag_list = []
        try:
            df = self.linked['Beam Diff'].dropna()
            linked_bag_list = df.values.tolist()
            min_num = int(min(linked_bag_list))
            if min_num > 0:                 # check if greater than 0, set to 0
                min_num = 0
            max_num = int(max(linked_bag_list))

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

        count = [0] * (max_num + 1)        # choose the largest num as length of count
        
        for num in linked_bag_list:
            count[int(num)] += 1            # update every number's count

        max_count = max(count)

        setBar = QBarSet('Beam Difference Occurrence')
        setBar.append(count)
        brush = QBrush(QColor(0x57B1FD))
        pen = QPen(QColor(0x57B1FD))
        pen.setWidth(2)
        setBar.setPen(pen)  
        setBar.setBrush(brush)

        series = QBarSeries()
        series.append(setBar)

        chart = QChart()
        chart.setTheme(QChart.ChartThemeBlueIcy)
        font = QFont()
        font.setPixelSize(18)
        chart.setTitleFont(font)

        chart.setTitle('Linked Bins Histogram')
        chart.addSeries(series)
        chart.setAnimationOptions(QChart.SeriesAnimations)

        axisX = QValueAxis()
        axisX.setTitleText("Attenuation Window")
        axisX.setRange(min_num, max_num+20)
        chart.setAxisX(axisX, series)

        axisY = QValueAxis()
        axisY.setTitleText("Frequency")
        axisY.setRange(0, max_count+20)
        chart.setAxisY(axisY, series)

        chart.legend().hide()

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

        return chartView
コード例 #18
0
ファイル: modeldata.py プロジェクト: xiangnidj0910/Examples
    def __init__(self, parent=None):
        super(TableWidget, self).__init__(parent)

        # Create a simple model for storing data.
        model = CustomTableModel()

        # Create the table view and add the model to it.
        tableView = QTableView()
        tableView.setModel(model)
        tableView.horizontalHeader().setSectionResizeMode(QHeaderView.Stretch)
        tableView.verticalHeader().setSectionResizeMode(QHeaderView.Stretch)

        chart = QChart()
        chart.setAnimationOptions(QChart.AllAnimations)

        # Series 1.
        series = QLineSeries()
        series.setName("Line 1")

        mapper = QVXYModelMapper(self)
        mapper.setXColumn(0)
        mapper.setYColumn(1)
        mapper.setSeries(series)
        mapper.setModel(model)
        chart.addSeries(series)

        # Get the color of the series and use it for showing the mapped area.
        seriesColorHex = self._series_color(series)
        model.addMapping(seriesColorHex, QRect(0, 0, 2, model.rowCount()))

        # Series 2.
        series = QLineSeries()
        series.setName("Line 2")

        mapper = QVXYModelMapper(self)
        mapper.setXColumn(2)
        mapper.setYColumn(3)
        mapper.setSeries(series)
        mapper.setModel(model)
        chart.addSeries(series)

        # Get the color of the series and use it for showing the mapped area.
        seriesColorHex = self._series_color(series)
        model.addMapping(seriesColorHex, QRect(2, 0, 2, model.rowCount()))

        chart.createDefaultAxes()
        chartView = QChartView(chart)
        chartView.setRenderHint(QPainter.Antialiasing)
        chartView.setMinimumSize(640, 480)

        # Create the main layout.
        mainLayout = QGridLayout()
        mainLayout.addWidget(tableView, 1, 0)
        mainLayout.addWidget(chartView, 1, 1)
        mainLayout.setColumnStretch(1, 1)
        mainLayout.setColumnStretch(0, 0)
        self.setLayout(mainLayout)
コード例 #19
0
    def beforeDelay(self):
        print("in before delay bar")
        min_num, max_num = 0, 100
        max_count = 0
        total_stopped_time = []
        try:
            total_stopped_time = self.tm.total_stopped_time
            max_num = max(total_stopped_time)
        except AttributeError:
            self.statusbar.showMessage('Data not ready')

        count = total_stopped_time
        count = [0] * (int(max_num) + 1
                       )  # choose the largest num as length of count

        for num in total_stopped_time:
            count[int(num)] += 1  # update every number's count

        max_count = max(count)
        print(len(total_stopped_time), max_count)
        setBar = QBarSet('stop time')
        setBar.append(count)
        brush = QBrush(QColor(0x57B1FD))
        pen = QPen(QColor(0x57B1FD))
        pen.setWidth(2)
        setBar.setPen(pen)
        setBar.setBrush(brush)

        series = QBarSeries()
        series.append(setBar)

        chart = QChart()
        font = QFont()
        font.setPixelSize(18)
        chart.setTitleFont(font)

        chart.setTitle('Stop time Histogram (before)')
        chart.addSeries(series)
        chart.setAnimationOptions(QChart.SeriesAnimations)

        axisX = QValueAxis()
        axisX.setRange(min_num, max_num + 20)
        chart.setAxisX(axisX, series)

        axisY = QValueAxis()
        axisY.setRange(0, max_count + 20)
        chart.setAxisY(axisY, series)

        chart.legend().setVisible(True)
        chart.legend().setAlignment(Qt.AlignBottom)

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

        # MainWindow.setCentralWidget(chartView)
        return chartView
コード例 #20
0
    def __init__(self, parent=None):
        super(TableWidget, self).__init__(parent)

        # Create a simple model for storing data.
        model = CustomTableModel()

        # Create the table view and add the model to it.
        tableView = QTableView()
        tableView.setModel(model)
        tableView.setMinimumWidth(300)
        tableView.horizontalHeader().setSectionResizeMode(QHeaderView.Stretch)
        tableView.verticalHeader().setSectionResizeMode(QHeaderView.Stretch)

        chart = QChart()
        chart.setAnimationOptions(QChart.AllAnimations)

        # Series 1.
        series = QBarSeries()

        first = 3
        count = 5
        mapper = QVBarModelMapper(self)
        mapper.setFirstBarSetColumn(1)
        mapper.setLastBarSetColumn(4)
        mapper.setFirstRow(first)
        mapper.setRowCount(count)
        mapper.setSeries(series)
        mapper.setModel(model)
        chart.addSeries(series)

        # Get the color of the series and use it for showing the mapped area.
        for i, barset in enumerate(series.barSets()):
            seriesColorHex = hex(barset.brush().color().rgb()).upper()
            if seriesColorHex.endswith('L'):
                seriesColorHex = seriesColorHex[:-1]
            seriesColorHex = '#' + seriesColorHex[-6:]
            model.addMapping(seriesColorHex,
                             QRect(1 + i, first, 1, barset.count()))

        categories = ["April", "May", "June", "July", "August"]
        axis = QBarCategoryAxis(chart)
        axis.append(categories)
        chart.createDefaultAxes()
        chart.setAxisX(axis, series)

        chartView = QChartView(chart)
        chartView.setRenderHint(QPainter.Antialiasing)
        chartView.setMinimumSize(640, 480)

        # Create the main layout.
        mainLayout = QGridLayout()
        mainLayout.addWidget(tableView, 1, 0)
        mainLayout.addWidget(chartView, 1, 1)
        mainLayout.setColumnStretch(1, 1)
        mainLayout.setColumnStretch(0, 0)
        self.setLayout(mainLayout)
コード例 #21
0
class VLineChartView(QChartView):
    def __init__(self):
        super(VLineChartView, self).__init__()
        self.stocks = read_tick_data()
        self.category = [
            trade_date[4:] for trade_date in self.stocks['trade_date']
        ]
        self.resize(800, 300)
        self.initChart()

    def initChart(self):
        self._chart = QChart(title='数量')
        self._chart.setAnimationOptions(QChart.SeriesAnimations)
        series = QStackedBarSeries()
        series.setName('数量')
        bar_red = QBarSet('red')
        bar_red.setColor(Qt.red)
        bar_green = QBarSet('green')
        bar_green.setColor(Qt.green)
        for _, stock in self.stocks.iterrows():
            if stock['open'] < stock['close']:
                bar_red.append(stock['vol'] / 100)
                bar_green.append(0)
            else:
                bar_red.append(0)
                bar_green.append(stock['vol'] / 100)

        series.append(bar_red)
        series.append(bar_green)
        self._chart.addSeries(series)
        self._chart.createDefaultAxes()
        self._chart.setLocalizeNumbers(True)
        axis_x = self._chart.axisX()
        axis_y = self._chart.axisY()
        axis_x.setGridLineVisible(False)
        axis_y.setGridLineVisible(False)
        axis_y.setLabelFormat("%.2f")
        axis_x.setCategories(self.category)
        max_p = self.stocks[[
            'vol',
        ]].stack().max() / 100 + 10
        min_p = self.stocks[[
            'vol',
        ]].stack().min() / 100 - 10
        axis_y.setRange(min_p, max_p)

        # chart的图例
        legend = self._chart.legend()
        legend.hide()
        # 设置图例由Series来决定样式
        # legend.setMarkerShape(QLegend.MarkerShapeFromSeries)

        self.setChart(self._chart)
        self._chart.layout().setContentsMargins(0, 0, 0, 0)
        # self._chart.setMargins(QMargins(0, 0, 0, 0))
        self._chart.setBackgroundRoundness(0)
コード例 #22
0
    def afterDelay(self):
        # print("in after delay bar")
        min_num, max_num = 0, 100
        max_count = 0
        total_stopped_after_delay = []
        count = [0] * (int(max_num) + 1)        # choose the largest num as length of count
        try:
            total_stopped_after_delay = self.tm.total_stopped_after_delay
            max_num = max(total_stopped_after_delay)
            count = [0] * (int(max_num) + 1)        # choose the largest num as length of count
                 
            for num in total_stopped_after_delay:
                count[int(num)] += 1            # update every number's count

            max_count = max(count)

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

        setBar = QBarSet('Stop Time Occurrence')
        setBar.append(count)
        brush = QBrush(QColor(0xA6E22E))		# Green
        pen = QPen(QColor(0xA6E22E))			# Green
        pen.setWidth(2)
        setBar.setPen(pen)  
        setBar.setBrush(brush)

        series = QBarSeries()
        series.append(setBar)

        chart = QChart()
        font = QFont()
        font.setPixelSize(18)
        chart.setTitleFont(font)

        chart.setTitle('Stop time Occurrence (after)')
        chart.addSeries(series)
        chart.setAnimationOptions(QChart.SeriesAnimations)

        axisX = QValueAxis()
        axisX.setRange(min_num, max_num+20)
        chart.setAxisX(axisX, series)

        axisY = QValueAxis()
        axisY.setRange(0, max_count+20)
        chart.setAxisY(axisY, series)

        chart.legend().setVisible(True)
        chart.legend().setAlignment(Qt.AlignBottom)

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

        # MainWindow.setCentralWidget(chartView)
        return chartView   
コード例 #23
0
ファイル: tablewidget.py プロジェクト: eyllanesc/QtExamples
    def __init__(self, parent=None):
        super().__init__(parent)

        self.m_model = CustomTableModel()

        tableView = QTableView()
        tableView.setModel(self.m_model)
        tableView.setMinimumWidth(300)
        tableView.horizontalHeader().setSectionResizeMode(QHeaderView.Stretch)
        tableView.verticalHeader().setSectionResizeMode(QHeaderView.Stretch)
        self.m_model.setParent(tableView)

        chart = QChart()
        chart.setAnimationOptions(QChart.AllAnimations)

        series = QBarSeries()

        first = 3
        count = 5
        mapper = QVBarModelMapper(self)
        mapper.setFirstBarSetColumn(1)
        mapper.setLastBarSetColumn(4)
        mapper.setFirstRow(first)
        mapper.setRowCount(count)
        mapper.setSeries(series)
        mapper.setModel(self.m_model)
        chart.addSeries(series)

        seriesColorHex = "#000000"

        barsets = series.barSets()
        for i, barset in enumerate(barsets):
            seriesColorHex = barset.brush().color().name()
            self.m_model.addMapping(
                seriesColorHex, QRect(1 + i, first, 1, barset.count())
            )

        categories = ("April", "May", "June", "July", "August")
        axisX = QBarCategoryAxis()
        axisX.append(categories)
        chart.addAxis(axisX, Qt.AlignBottom)
        series.attachAxis(axisX)
        axisY = QValueAxis()
        chart.addAxis(axisY, Qt.AlignLeft)
        series.attachAxis(axisY)

        chartView = QChartView(chart)
        chartView.setRenderHint(QPainter.Antialiasing)
        chartView.setMinimumSize(640, 480)

        mainLayout = QGridLayout(self)
        mainLayout.addWidget(tableView, 1, 0)
        mainLayout.addWidget(chartView, 1, 1)
        mainLayout.setColumnStretch(1, 1)
        mainLayout.setColumnStretch(0, 0)
コード例 #24
0
ファイル: windows.py プロジェクト: MR-Geri/cinema
class WindowStatic(QWidget):
    def __init__(self,
                 window: WindowCinemas = None,
                 title: str = '',
                 base: list = None) -> None:
        super().__init__()
        self.title = title
        self.window = window.static
        self.base = base
        self._init_ui()

    def _init_chart(self) -> None:
        series = QBarSeries()
        axis_x = QBarCategoryAxis()
        axis_y = QValueAxis()
        data_set = defaultdict(int)
        for title, money in self.base:
            data_set[title] += money
        for title, money in data_set.items():
            bar = QBarSet(title)
            axis_x.append(title)
            bar.append(money)
            series.append(bar)
        #
        self.chart = QChart()
        self.chart.addSeries(series)
        self.chart.setAnimationOptions(QChart.SeriesAnimations)
        #
        series.attachAxis(axis_x)
        self.chart.addAxis(axis_x, Qt.AlignBottom)
        axis_y.setRange(0, max(data_set.values()))
        axis_y.setTickCount(11)
        self.chart.addAxis(axis_y, Qt.AlignLeft)
        series.attachAxis(axis_y)
        #
        self.chart.legend().setVisible(True)
        self.chart.legend().setAlignment(Qt.AlignBottom)

    def _init_ui(self) -> None:
        self.window.resize(1000, 900)
        self._init_chart()
        self.chartView = QChartView(self.chart)
        self.chartView.setRenderHint(QPainter.Antialiasing)
        self.label_title = QLabel(self.title)
        #
        self.label_title.setFont(QFont('MS Shell Dlg 2', 20))
        #
        self.label_title.setAlignment(Qt.AlignHCenter | Qt.AlignHCenter)
        #
        self.layout = QVBoxLayout(self, spacing=0)
        self.layout.setContentsMargins(10, 0, 10, 0)
        #
        self.layout.addWidget(self.label_title)
        self.layout.addWidget(self.chartView)
コード例 #25
0
ファイル: 01-Chart-Demo.py プロジェクト: cyn9/Programming
class Window(QMainWindow):
    def __init__(self):
        super().__init__()

        self.setWindowTitle("PyQtChart Demo")
        self.setGeometry(500, 275, 650, 500)

        self.show()
        self.createLineChart()

    def createLineChart(self):
        self.font = QFont("Arial")
        self.font.setPixelSize(16)
        self.font.setBold(True)

        self.pen = QPen(QColor(0, 153, 0))
        self.pen.setWidth(3)

        self.series = QLineSeries(self)
        self.series.setPen(self.pen)

        self.x = np.arange(0, 2 * np.pi, 0.01)

        for i in self.x:
            self.series.append(i, np.sin(i))

        self.chart = QChart()
        self.chart.addSeries(self.series)
        self.chart.setAnimationOptions(QChart.SeriesAnimations)
        self.chart.setTitleFont(self.font)
        self.chart.setTitleBrush(QBrush(Qt.blue))
        self.chart.setTitle("Line Chart Demo")

        self.chart.legend().setVisible(True)
        self.chart.legend().setAlignment(Qt.AlignBottom)

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

        self.axisX = QValueAxis()
        self.axisX.setRange(0, 2 * np.pi)
        self.axisX.setTickCount(6)
        self.axisX.setLabelFormat("%.1f")
        self.axisX.setTitleText("x")

        self.axisY = QValueAxis()
        self.axisY.setRange(0, 100)
        self.axisY.setLabelFormat("%d")
        self.axisY.setTitleText("sin(x)")

        self.chart.addAxis(self.axisX, Qt.AlignBottom)
        self.chart.addAxis(self.axisY, Qt.AlignLeft)

        self.setCentralWidget(self.chartview)
コード例 #26
0
class pieChartView(QChartView):
    def __init__(self, *args, **kwargs):
        super(pieChartView, self).__init__(*args, **kwargs)
        self.initChart()
        self.refresh()

    def initChart(self):
        self._chart = QChart()
        # 调整边距
        self._chart.layout().setContentsMargins(0, 0, 0, 0)  # 外界
        self._chart.setMargins(QMargins(3, 0, 3, 0))  # 内界
        self._chart.setBackgroundRoundness(0)
        self._chart.setBackgroundVisible(False)
        # 设置主题
        self._chart.setTheme(QChart.ChartThemeBlueIcy)
        # 抗锯齿
        self.setRenderHint(QPainter.Antialiasing)
        # 开启动画效果
        self._chart.setAnimationOptions(QChart.SeriesAnimations)
        self._series = QPieSeries()
        self._series.setPieSize(0.8)
        self._chart.addSeries(self._series)
        self.setChart(self._chart)

    def refresh(self):
        # 提示widget
        self.toolTipWidget = GraphicsProxyWidget(self._chart)

    def mouseMoveEvent(self, event):
        super(pieChartView, self).mouseMoveEvent(event)
        pos = event.pos()
        x = pos.x()
        y = pos.y()
        # 得到在坐标系中的所有区域
        self.min_x, self.max_x = self._chart.geometry().width(
        ) * 0.2, self._chart.geometry().width() * 0.8
        self.min_y, self.max_y = self._chart.geometry().height(
        ) * 0.2, self._chart.geometry().height() * 0.9
        serie = self._chart.series()[0]
        slices = [(slice, slice.value()) for slice in serie.slices()]
        if self.min_x <= x <= self.max_x and self.min_y <= y <= self.max_y:
            t_width = self.toolTipWidget.width()
            t_height = self.toolTipWidget.height()
            title = "数据组成"
            # 如果鼠标位置离右侧的距离小于tip宽度
            x = pos.x() - t_width if self.width() - \
                                     pos.x() - 20 < t_width else pos.x()
            # 如果鼠标位置离底部的高度小于tip高度
            y = pos.y() - t_height if self.height() - \
                                      pos.y() - 20 < t_height else pos.y()
            self.toolTipWidget.show(title, slices, QPoint(x, y))
        else:
            self.toolTipWidget.hide()
コード例 #27
0
    def createSummaryBar(self):
        # self.dp.dfinal

        series = QPieSeries()
        labelfont = QFont()
        labelfont.setPixelSize(11)
        try:
            series.append("Linked", len(self.linked.index))
            series.append("Unlinked", len(self.unlinked.index))
            # slices = QPieSlice()
            slices1 = series.slices()[1]
            slices1.setExploded()
            slices1.setLabelVisible()
            slices1.setPen(QPen(QColor(0x57B1FD), 2))
            slices1.setBrush(QBrush(QColor(0xfdb157)))
            slices1.setLabelPosition(QPieSlice.LabelOutside)
            slices1.setLabel(
                ("{0} {1:.2f}%").format("Unlinked",
                                        100 * slices1.percentage()))
            slices1.setLabelFont(labelfont)

            # slices.setPen(QPen(Qt.darkGreen, 2))
            # slices.setBrush(QBrush(QColor(0xfdb157)))
        except AttributeError:
            self.statusbar.showMessage('Data not ready')
            series.append("Total", 1)

        slices = series.slices()[0]

        slices.setBrush(QBrush(QColor(0x57B1FD)))
        # slices.setLabel(("%1%").format(100*slices.percentage(), 0, 'f', 1))
        # slices.setLabelPosition(QPieSlice.LabelInsideHorizontal)
        if len(series.slices()
               ) == 2:  # display "linked" label only at data was processed
            slices.setLabelVisible()
            slices.setLabel(("{0} {1:.2f}%").format("Linked",
                                                    100 * slices.percentage()))
            slices.setLabelFont(labelfont)

        chart = QChart()
        font = QFont()
        font.setPixelSize(18)
        chart.setTitleFont(font)

        chart.addSeries(series)
        chart.setAnimationOptions(QChart.SeriesAnimations)
        chart.setTitle("Total")
        chart.legend().hide()

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

        return chartView
コード例 #28
0
ファイル: main.py プロジェクト: AndrewDid/TPR_course_project
    def createChart(self, names, values, title):
        series = QPieSeries()
        for name, value in zip(names, values):
            series.append(name + " " + str(value) + "%", value)

        chart = QChart()
        chart.addSeries(series)
        chart.setAnimationOptions(QChart.SeriesAnimations)
        chart.setTitle(title)
        chart.legend().setVisible(True)

        return chart
コード例 #29
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
コード例 #30
0
    def method_pie(self, year):
        pie_chart = QChart()
        pie_chart.legend().hide()
        pie_chart.addSeries(PaymentMethods(self.data, year))
        pie_chart.createDefaultAxes()
        pie_chart.setAnimationOptions(QChart.SeriesAnimations)
        pie_chart.setTitle("Payment methods")

        pie_chart.legend().setVisible(True)
        pie_chart.legend().setAlignment(Qt.AlignBottom)

        self.ui.v_method_pie.setChart(pie_chart)