음수 막대를 사용한 기온 기록 표시
참고: 이 내용은 ‘위젯이 포함된 차트 갤러리’ 예제의 일부입니다. 이 예제에서는 기온 데이터를 사용합니다.

먼저 두 개의 막대 세트를 생성하고 데이터를 추가합니다. 한 세트는 최저 기온을, 다른 세트는 최고 기온을 나타냅니다.
auto low = new QBarSet("Min");
auto high = new QBarSet("Max");
*low << -52 << -50 << -45.3 << -37.0 << -25.6 << -8.0
<< -6.0 << -11.8 << -19.7 << -32.8 << -43.0 << -48.0;
*high << 11.9 << 12.8 << 18.5 << 26.5 << 32.0 << 34.8
<< 38.2 << 34.8 << 29.8 << 20.4 << 15.1 << 11.8;시리즈를 생성하고 바 세트를 해당 시리즈에 추가합니다. 시리즈가 바 세트의 소유권을 갖게 됩니다.
auto series = new QStackedBarSeries;
series->append(low);
series->append(high);여기서 차트 객체를 생성하고 시리를 추가합니다. setTitle을 사용하여 차트의 제목을 설정한 다음, setAnimationOptions(QChart::SeriesAnimations)를 호출하여 시리의 애니메이션을 활성화합니다.
auto chart = new QChart;
chart->addSeries(series);
chart->setTitle("Temperature records in Celcius");
chart->setAnimationOptions(QChart::SeriesAnimations);범주를 축에 표시하려면 QBarCategoryAxis를 생성해야 합니다. 여기서는 범주 목록을 사용하여 범주 축을 생성하고, 이를 차트의 하단에 정렬하여 x축으로 추가합니다. 차트가 해당 축의 소유권을 갖습니다. y축의 경우 값 축을 사용하며, 왼쪽에 정렬합니다. 자동 스케일링보다 더 깔끔한 결과를 얻을 수 있도록 y축의 범위를 변경합니다.
QStringList categories = {
"Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"
};
auto axisX = new QBarCategoryAxis;
axisX->append(categories);
axisX->setTitleText("Month");
chart->addAxis(axisX, Qt::AlignBottom);
auto axisY = new QValueAxis;
axisY->setRange(-52, 52);
axisY->setTitleText("Temperature [°C]");
chart->addAxis(axisY, Qt::AlignLeft);
series->attachAxis(axisX);
series->attachAxis(axisY);또한 범례를 표시하고자 합니다. 이를 위해 차트에서 범례 포인터를 가져와 표시되도록 설정합니다. 또한 정렬을 ` Qt::AlignBottom`로 설정하여 범례를 차트 하단에 배치합니다.
chart->legend()->setVisible(true);
chart->legend()->setAlignment(Qt::AlignBottom);마지막으로 차트를 뷰에 추가합니다.
createDefaultChartView(chart);이제 차트를 표시할 준비가 되었습니다.
© 2026 The Qt Company Ltd. Documentation contributions included herein are the copyrights of their respective owners. The documentation provided herein is licensed under the terms of the GNU Free Documentation License version 1.3 as published by the Free Software Foundation. Qt and respective logos are trademarks of The Qt Company Ltd. in Finland and/or other countries worldwide. All other trademarks are property of their respective owners.