非常小的窗口都能显示
QT += core gui charts
#include <QtCharts>
using namespace QtCharts;
//创建饼状图
void MainWindow::createpieSewies()
{
//饼状图
QPieSeries * my_pieSeries = new QPieSeries();
//中间圆与大圆的比例
my_pieSeries->setHoleSize(0.35);
//扇形及数据
QPieSlice *pieSlice_running = new QPieSlice();
pieSlice_running->setValue(25);//扇形占整个圆的百分比
pieSlice_running->setLabel("XXX");
pieSlice_running->setLabelVisible();
pieSlice_running->setColor(QColor("#4cb9cf"));
pieSlice_running->setLabelColor(QColor("#4cb9cf"));
pieSlice_running->setBorderColor(QColor("#4cb9cf"));
pieSlice_running->setBorderColor(QColor());
my_pieSeries->append(pieSlice_running);
QPieSlice *pieSlice_noconnect = new QPieSlice();
pieSlice_noconnect->setValue(25);
pieSlice_noconnect->setLabel("YYY");
pieSlice_noconnect->setColor(QColor("#53b666"));
pieSlice_noconnect->setLabelColor(QColor("#53b666"));
pieSlice_noconnect->setBorderColor(QColor("#53b666"));
pieSlice_noconnect->setLabelVisible();//设置标签可见,缺省不可见
my_pieSeries->append(pieSlice_noconnect);
QPieSlice *pieSlice_idle = new QPieSlice();
pieSlice_idle->setValue(50);
pieSlice_idle->setLabel("WWW");
pieSlice_idle->setLabelVisible();
pieSlice_idle->setColor(QColor("#2f89cf"));
pieSlice_idle->setLabelColor(QColor("#2f89cf"));
pieSlice_idle->setBorderColor(QColor("#2f89cf"));
my_pieSeries->append(pieSlice_idle);
// 图表视图
QChart *chart = new QChart();
chart->setTitle("FFFFF");
chart->addSeries(my_pieSeries);
chart->setAnimationOptions(QChart::SeriesAnimations);
chart->legend()->setAlignment(Qt::AlignBottom);
chart->legend()->setBackgroundVisible(false);
chart->legend()->setFont(QFont("黑体", 8)) ; // 图例字体
chart->setTitleBrush(QColor("#808396"));
chart->legend()->setLabelColor(QColor("#808396"));
QChartView *chartView = new QChartView();
chartView = new QChartView(ui->widget);
chartView->setRenderHint(QPainter::Antialiasing);
chartView->setRenderHint(QPainter::NonCosmeticDefaultPen);
chartView->setChart(chart);
ui->gridLayout->addWidget(chartView);
}