[PyQt] PyQt Chart Documentation

Phil Thompson phil at riverbankcomputing.com
Thu Aug 25 11:25:41 BST 2016


> On 25 Aug 2016, at 10:17 am, Nick <napperley at gmail.com> wrote:
> 
> Thanks! Realised that there was an extra "s" that needed to be removed at the end of the import. Got the Bar chart example working based on the one in the Qt C++ documentation. However the axis legend doesn't appear. Below is the function that creates the QChart which is used in the QChartView:
> 
> ===================================================
> def create_bar_chart(self):
>         set0 = QBarSet('Jane')
>         set1 = QBarSet('John')
>         series = QBarSeries()
>         chart = QChart()
>         axis = QBarCategoryAxis()
>         categories = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun']
>         
>         set0.append([1, 2, 3, 4, 5, 6])
>         set1.append([5, 0, 0, 4, 0, 7])
>         series.append(set0)
>         series.append(set1)
>         chart.addSeries(series)
>         axis.append(categories)
>         
>         chart.setTitle('Simple barchart example')
>         chart.createDefaultAxes()
>         chart.setAxisX(axis, series)
>         chart.legend().setAlignment(Qt.AlignBottom)
>         return chart
> ===================================================

It's an ownership bug in PyQtChart.  To work around do...

    axis = QBarCategoryAxis(chart)

Phil


More information about the PyQt mailing list