エリア・チャートの作成
注: これはCharts with Widgets Galleryの例の一部です。
エリア・チャートを作成するには、2つのQLineSeries インスタンスが必要です。この2つのインスタンスがエリアの上下の境界を定義します。
auto series0 = new QLineSeries; auto series1 = new QLineSeries;
両方の系列にデータを追加し、stream演算子を使います。
*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);
最後に、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.