//柱状图
// 创建柱状图数据
QBarSet *set0 = new QBarSet("");
*set0 << 1601 << 974 << 655 << 362;
QBarSeries *series = new QBarSeries();
series->append(set0);
set0->setColor(QColor("#F5834B"));
// 创建柱状图
QChart *chart_center_Bar = new QChart();
chart_center_Bar->addSeries(series);
chart_center_Bar->setTitle("");
chart_center_Bar->setAnimationOptions(QChart::SeriesAnimations);
chart_center_Bar->setBackgroundVisible(false);
// 设置柱子宽度
series->setBarWidth(0.2); // 设置柱子宽度为0.5
// 创建X轴和Y轴
QStringList categories;
categories << u8"A" << u8"B" << u8"C" << u8"D" ;
QBarCategoryAxis *axisX = new QBarCategoryAxis();
axisX->append(categories);
axisX->setLabelsFont(QFont("Arial", 6));
axisX->setLabelsColor(Qt::white);
axisX->setGridLineVisible(false);
chart_center_Bar->addAxis(axisX, Qt::AlignBottom);
series->attachAxis(axisX);
QValueAxis *axisY = new QValueAxis();
axisY->setGridLineVisible(false);
axisY->setLabelsColor(Qt::white);
chart_center_Bar->addAxis(axisY, Qt::AlignLeft);
series->attachAxis(axisY);
//图例
chart_center_Bar->legend()->setAlignment(Qt::AlignBottom);
chart_center_Bar->legend()->setVisible(false);;
// 创建柱状图视图
QChartView *chart_center_BarView = new QChartView(chart_center_Bar);
chart_center_BarView->setRenderHint(QPainter::Antialiasing);
chart_center_BarView->setStyleSheet("background-color: transparent;");
//加入布局
QVBoxLayout* layout_centers_Bar = new QVBoxLayout;
layout_centers_Bar->setContentsMargins(0, 0, 0, 0);
layout_centers_Bar->addWidget(chart_center_BarView);
ui->widget_centers_Bar->setLayout(layout_centers_Bar);
ui->widget_centers_Bar->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
推荐一个零声学院项目课,个人觉得老师讲得不错,分享给大家:
零声白金学习卡(含基础架构/高性能存储/golang云原生/音视频/Linux内核)
https://xxetb.xet.tech/s/3Zqhgt