범주형 차트 만들기

참고: 이 내용은 '위젯이 포함된 차트 갤러리' 예제의 일부입니다.

그래프 예시 이미지

영역 차트를 만들려면 두 개의 QLineSeries 인스턴스가 필요합니다. 이 인스턴스들은 영역의 상한과 하한을 정의하게 됩니다.

auto series0 = new QLineSeries;
auto series1 = new QLineSeries;

두 시리즈 모두에 데이터를 추가하고 스트림 연산자를 사용합니다.

*series0 << QPointF(1, 5) << QPointF(3, 7) << QPointF(7, 6) << QPointF(9, 7) << QPointF(12, 6)
         << QPointF(16, 7) << QPointF(18, 5);
*series1 << QPointF(1, 3) << QPointF(3, 4) << QPointF(7, 3) << QPointF(8, 2) << QPointF(12, 3)
         << QPointF(16, 4) << QPointF(18, 3);

이제 두 개의 선 시리즈 객체를 사용하여 QAreaSeries 인스턴스를 생성합니다. 사용자 정의 그라데이션 채우기와 윤곽선의 너비를 설정합니다.

auto series = new QAreaSeries(series0, series1);
series->setName("Batman");
QPen pen(0x059605);
pen.setWidth(3);
series->setPen(pen);

QLinearGradient gradient(QPointF(0, 0), QPointF(0, 1));
gradient.setColorAt(0.0, 0x3cc63c);
gradient.setColorAt(1.0, 0x26f626);
gradient.setCoordinateMode(QGradient::ObjectBoundingMode);
series->setBrush(gradient);

마지막으로 QChartView 인스턴스를 생성하고, 제목을 설정하며, 안티앨리어싱을 적용하고, 영역 시리즈를 추가합니다. 또한 기본 축을 생성하고 해당 축의 범위를 지정합니다.

auto chart = new QChart;
chart->addSeries(series);
chart->setTitle("Simple Area Chart");
chart->createDefaultAxes();
chart->axes(Qt::Horizontal).first()->setRange(0, 20);
chart->axes(Qt::Vertical).first()->setRange(0, 10);

이제 차트를 표시할 준비가 되었습니다.

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.