QT 扇形图
ui->widget->setStyleSheet("QWidget{background-color:#222648;}"); series = new QPieSeries(); series->append("20%", 2); series->append("50%", 5); series->append("30%", 3); series->setLabelsVisible(); QPieSlice *slice_red = series->slices().at(0); //添加扇区 QPieSlice *slice_green = series->slices().at(1); QPieSlice *slice_black = series->slices().at(2); slice_red->setColor(QColor(199,38,22)); //设置颜色 slice_green->setColor(QColor(0,165,94)); slice_black->setColor(QColor(54,54,54)); slice_red->setLabelColor(QColor(255,255,255)); //设置label的颜色 slice_green->setLabelColor(QColor(255,255,255)); slice_black->setLabelColor(QColor(255,255,255)); //slice_red->setExploded();//展开 QFont font; font.setPointSize(9); //设置字体大小,如果字体过大容易显示不出来 slice_red->setLabelFont(font); slice_green->setLabelFont(font); slice_black->setLabelFont(font); QChart *chart = new QChart(); chart->addSeries(series); chart->legend()->hide(); chart->setBackgroundBrush(QBrush(QColor(34,38,72))); chart->setAnimationOptions(QChart::AllAnimations);//设置启用或禁用动画 QChartView *chartview = new QChartView(chart); chartview->setRenderHint(QPainter::Antialiasing); chartview->setParent(ui->widget); chartview->resize(ui->widget->size());
在使用时,需要在pro文件里面添加一行代码
QT += charts