음수 막대가 있는 온도 기록 표시하기
참고: 이 예는 위젯이 있는 차트 갤러리 예제의 일부입니다. 이 예에서는 온도 데이터를 사용합니다.
먼저 두 개의 막대 세트를 만들고 여기에 데이터를 추가합니다. 한 세트는 최저 온도를 나타내고 다른 세트는 최고 온도를 나타냅니다.
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);
차트를 표시할 준비가 되었습니다.
© 2025 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.