QChart *ThemeWidget::createBarChart(int valueCount) const
{
Q_UNUSED(valueCount);
QChart *chart = new QChart();
chart->setTitle("Bar chart");
QStackedBarSeries *series = new QStackedBarSeries(chart);
for (int i(0); i < m_dataTable.count(); i++) {
QBarSet *set = new QBarSet("Bar set" + QString::number(i));
for (const Data &data : m_dataTable[i])//遍历数据??为什么括号内是那样的
*set << data.first.y();
series->append(set);
}
chart->addSeries(series);
//设置坐标轴
chart->createDefaultAxes();
chart->axes(Qt::Vertical).first()->setRange(0, m_valueMax * 2);
// Add space to label to add space between labels and axis
QValueAxis *axisY = qobject_cast<QValueAxis*>(chart->axes(Qt::Vertical).first());
Q_ASSERT(axisY);
axisY->setLabelFormat("%.1f ");
return chart;
}
想问一下return chart之前的三行代码用处是什么,我注释掉掉后似乎图表没有变化。
还有QBarSet *set = new QBarSet("Bar set" + QString::number(i));中QString::number(i)的作用是什么。
求大佬回答一下