图
代码
QLineSeries * seriesReality = new QLineSeries ( ) ; seriesReality-> setColor ( Qt:: green) ; QLineSeries * seriesTar = new QLineSeries ( ) ; seriesTar-> setColor ( Qt:: yellow) ; QStringList categories; for ( int i = 0 ; i < 12 ; i++ ) { categories << QString :: number ( i + 1 ) ; seriesReality-> append ( i, i+ 1 ) ; seriesTar-> append ( i, i + 2 ) ; } QPen pen; pen. setWidth ( 2 ) ; seriesReality-> setPen ( pen) ; seriesTar-> setPen ( pen) ; seriesReality-> setColor ( Qt:: green) ; seriesTar-> setColor ( Qt:: yellow) ; seriesReality-> setPointLabelsVisible ( true ) ; seriesTar-> setPointLabelsVisible ( true ) ; QChart * chart = new QChart ( ) ; chart-> addSeries ( seriesReality) ; chart-> addSeries ( seriesTar) ; chart-> setBackgroundVisible ( false ) ; chart-> legend ( ) -> hide ( ) ; QValueAxis* axisY = new QValueAxis; axisY-> setRange ( 0 , 20 ) ; axisY-> setLabelsColor ( QColor ( Qt:: GlobalColor:: black) ) ; axisY-> setGridLineColor ( QColor ( Qt:: GlobalColor:: black) ) ; chart-> addAxis ( axisY, Qt:: AlignLeft) ; seriesReality-> attachAxis ( axisY) ; seriesTar-> attachAxis ( axisY) ; QBarCategoryAxis * axisX = new QBarCategoryAxis ( ) ; axisX-> append ( categories) ; chart-> addAxis ( axisX, Qt:: AlignBottom) ; seriesReality-> attachAxis ( axisX) ; seriesTar-> attachAxis ( axisX) ; seriesReality-> setPointLabelsFormat ( "(@yPoint)" ) ; seriesTar-> setPointLabelsFormat ( "(@yPoint)" ) ; seriesReality-> setPointLabelsClipping ( false ) ; seriesTar-> setPointLabelsClipping ( false ) ; QChartView* chartView = new QChartView ( chart) ; chartView-> setRenderHint ( QPainter:: Antialiasing) ; setCentralWidget ( chartView) ;