Uso de varios ejes
Nota: Esto es parte del ejemplo de la Galería de Gráficos con Widgets.

Cree la instancia QChart, oculte la leyenda del gráfico y establezca su título.
auto chart = new QChart; chart->legend()->hide(); chart->setTitle("Multiple Vertical Axes in Chart");
Cree una instancia de QValueAxis que será utilizada como eje horizontal por ambas series y añádala a la parte inferior del gráfico. El eje puede ser compartido entre varias series, pero cada serie sólo puede tener un eje vertical y horizontal.
auto axisX = new QValueAxis; axisX->setTickCount(10); chart->addAxis(axisX, Qt::AlignBottom);
Cree la primera serie y añádale los datos. Finalmente, añada la serie al gráfico. Instancie su propio eje Y y añádalo al gráfico. A continuación, añada el eje X común y el eje Y específico de la serie. En este ejemplo, el color de la línea del eje es el mismo que el color de la serie para que sea posible distinguir qué eje está unido a qué serie.
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);
Prepare otra serie de forma similar. Esta vez se utiliza un tipo de eje diferente. Adicionalmente el color de las líneas de la rejilla también se establece para que sea el mismo que el color de la serie.
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);
Cree un objeto QChartView con QChart como parámetro.
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.