영역 차트 만들기
참고: 이것은 위젯이 있는 차트 갤러리 예제의 일부입니다.
영역 차트를 만들려면 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);
© 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.