여러 축 사용하기
참고: 이 내용은 ‘위젯이 포함된 차트 갤러리’ 예제의 일부입니다.

QChart 인스턴스를 생성하고, 차트의 범례를 숨긴 다음 제목을 설정합니다.
auto chart = new QChart;
chart->legend()->hide();
chart->setTitle("Multiple Vertical Axes in Chart");두 시리즈 모두에서 가로축으로 사용할 QValueAxis 인스턴스를 생성하고 차트 하단에 추가합니다. 축은 여러 시리즈에서 공유할 수 있지만, 각 시리즈는 세로축과 가로축을 각각 하나씩만 가질 수 있습니다.
auto axisX = new QValueAxis;
axisX->setTickCount(10);
chart->addAxis(axisX, Qt::AlignBottom);첫 번째 시리즈를 생성하고 데이터를 추가합니다. 마지막으로, 시리즈를 차트에 추가합니다. 시리즈 전용 Y축을 생성하여 차트에 추가합니다. 그런 다음 공통 X축과 시리즈 전용 Y축을 모두 연결합니다. 이 예제에서는 어떤 축이 어떤 시리즈에 연결되어 있는지 구분할 수 있도록 축 선의 색상을 시리즈의 색상과 동일하게 설정했습니다.
auto series = new QSplineSeries;
*series << QPointF(1, 5) << QPointF(3.5, 18) << QPointF(4.8, 7.5) << QPointF(10, 2.5);
chart->addSeries(series);
auto axisY = new QValueAxis;
axisY->setLinePenColor(series->pen().color());
chart->addAxis(axisY, Qt::AlignLeft);
series->attachAxis(axisX);
series->attachAxis(axisY);비슷한 방식으로 다른 시리즈를 준비합니다. 이번에는 다른 축 유형을 사용합니다. 또한 격자선의 색상도 시리즈의 색상과 동일하게 설정합니다.
series = new QSplineSeries;
*series << QPointF(1, 0.5) << QPointF(1.5, 4.5) << QPointF(2.4, 2.5) << QPointF(4.3, 12.5)
<< QPointF(5.2, 3.5) << QPointF(7.4, 16.5) << QPointF(8.3, 7.5) << QPointF(10, 17);
chart->addSeries(series);
auto axisY3 = new QCategoryAxis;
axisY3->append("Low", 5);
axisY3->append("Medium", 12);
axisY3->append("High", 17);
axisY3->setLinePenColor(series->pen().color());
axisY3->setGridLinePen((series->pen()));
chart->addAxis(axisY3, Qt::AlignRight);
series->attachAxis(axisX);
series->attachAxis(axisY3);QChart를 매개변수로 사용하여 QChartView 객체를 생성합니다.
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.