다중 축 사용

참고: 이 예는 위젯이 있는 차트 갤러리 예제의 일부입니다.

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);

© 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.