参考资料:

https://blog.csdn.net/lmhuanying1012/article/details/78454608

效果图:

 

     QPieSeries *series = new QPieSeries();
     //series->setHoleSize(0.35);
     series->append("10%", 1);
     series->append("20%", 2);
     series->append("70%", 7);
     series->setLabelsVisible();

     QPieSlice *slice_red = series->slices().at(0);
     QPieSlice *slice_green = series->slices().at(1);
     QPieSlice *slice_blue = series->slices().at(2);
     slice_red->setColor(QColor(255,0,0,255));
     slice_green->setColor(QColor(0,255,0,255));
     slice_blue->setColor(QColor(0,0,255,255));

     QChart *chart = new QChart();
     chart->addSeries(series);
     chart->setTitle("PieChart Example");
     chart->legend()->hide();

     QChartView *chartview = new QChartView(chart);
     chartview->setRenderHint(QPainter::Antialiasing);
     chartview->chart()->setTheme(QChart::ChartThemeBlueCerulean);
     chartview->chart()->legend()->setFont(QFont("Arial", 7));

     QVBoxLayout *vb = new QVBoxLayout(this);

     vb->addWidget(chartview);
     this->setLayout(vb);
posted on 2018-12-20 14:52  邶风  阅读(339)  评论(0编辑  收藏  举报