面積グラフの作成

注:これは 「ウィジェット付きグラフギャラリー」のサンプルの一部です。

グラフの例を示す画像

面積グラフを作成するには、2つの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);

次に、2つのラインシリーズオブジェクトを使用して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);

最後に、QLineSeriesインスタンスを作成し、タイトルを設定し、アンチエイリアシングを設定し、エリアシリーズを追加します。また、デフォルトの軸を作成し、それらの範囲を指定します。

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.