Qt 拡張機能 - QCustomPlot 描画の基本の概要

I. 概要

このチュートリアルでは、customPlot を QCustomPlot インスタンスへのポインターとして使用します。QtCreator でコントロールを作成すると、ui->customPlot (またはコントロールに付けた名前) を通じて対応するコントロールにアクセスできます。

CustomPlot->addGraph() を使用して、図面内に新しいグラフを作成できます。次に、customPlot->graph(0)->setData(…) などを介して、x と y (キーと値) を表す 2 つの QVector の形式で、いくつかのデータ ポイントをグラフに割り当てます。

QCustomPlot がx と y の代わりにキーと値という用語を使用する理由は、どの軸にどのような役割があるかをより柔軟に割り当てることができるようにするためですしたがって、左軸を「キー軸」として定義し、下の軸を「値軸」として定義すると、チャートの左側に正立したチャートを描くことができます。

デフォルトでは、QCustomPlot コントロールには 4 つの軸があります。customPlot->xAxis、yAxis、xAxis2、および QCPAxis タイプの yAxis2 で、それぞれ下軸、左軸、上軸、右軸に対応します。その範囲は、プロットのどの部分が現在表示されているかを定義します:customPlot->xAxis->setRange(- 1,1)。

画面に表示されているプロットに何らかの変更を加えるには、customPlot->replot() を呼び出します。これは、QPainter のfresh() と同じ、手動リフレッシュに相当します。コントロールのサイズが変更され、組み込みのユーザー インタラクションがトリガーされると、再描画が自動的に行われることに注意してください。たとえば、このようなユーザー インタラクションは、マウスで軸範囲をドラッグしたり、マウス ホイールでズームしたりすることです。

// 生成数据:
QVector<double> x(101), y(101); // initialize with entries 0..100
for (int i=0; i<101; ++i)
{
    
    
  x[i] = i/50.0 - 1; // x goes from -1 to 1
  y[i] = x[i]*x[i]; // let's plot a quadratic function
}
 
// create graph and assign data to it:
customPlot->addGraph();
customPlot->graph(0)->setData(x, y);

// give the axes some labels:
customPlot->xAxis->setLabel("x");
customPlot->yAxis->setLabel("y");

// set axes ranges, so we see all data:
customPlot->xAxis->setRange(-1, 1);
customPlot->yAxis->setRange(0, 1);
customPlot->replot();

出力は以下のようになります。

ここに画像の説明を挿入します

マーカーの目盛りとマーカーは、軸によって現在使用されている軸によって自動的に選択されます。この軸は QCPAxisTicker タイプのインスタンスであり、xAxis->ticker() などを通じてアクセスできます。

xAxis->ticker()->setTickCount(6) を通じて、自動的に作成しようとするティックのおおよその数を調整できます。デフォルトの軸スケールは単純な数値表示に最適ですが、時間スケール、カレンダー日付スケール、カテゴリ スケール、pi (またはその他の記号単位)、対数軸などの特殊なクラスもあります。詳細については、QCPAxisTicker のドキュメントを参照してください。

コントロールは軸の目盛りを自動的に計算し、これがデフォルトでオンになっているため、軸の目盛りラベル (数値) は、幅が広くなったとしてもコントロールの境界線を超えることはありません。目盛りラベルと軸ラベルにより多くのスペースが必要な場合は、軸の四角形が縮小されます。マージンを自動的に決定したくない場合は、customPlot->axisRect()->setAutoMargins(QCP::msNone) を呼び出してこの動作を無効にします。また、customPlot->axisRect()->setmargin(…) を使用してマージンを手動で調整することもできます。

2. 外観を変更する

1. グラフの種類

グラフの外観は多くの要因によって決まりますが、それらはすべて変更できます。最も重要な点は次のとおりです。

  • 線のスタイル:graph->setLineStyle(…) を呼び出します。可能なすべての線スタイルについては、QCPGraph::LineStyle のドキュメント、または紹介ページの線スタイルのデモのスクリーンショットを参照してください。
    ここに画像の説明を挿入します
列挙型 意味
lsNone データ点はどの直線にも接続されていません (例: データは散布パターンに従ってシンボルのみで表されます)
lsライン データ点は直線で結ばれています
lsStepLeft 線はステップとして描画されます。ステップの高さは左側のデータ ポイントの値です。
lsStepRight 線はステップとして描画されます。ステップの高さは正しいデータ ポイントの値です。
lsStepCenter ステップ サイズが 2 つのデータ ポイントの間にある場合、線はステップ サイズとして描画されます。
lsインパルス 各データ ポイントは、データ ポイントからゼロ値の線まで伸びる値軸に平行な線で表されます。
  • Line Pen : 実線、破線、点線、さまざまな幅、色、透明度など、QPainter フレームワークによって提供されるすべてのペンが利用可能です。設定されたブラシは、graph->setPen(...) によって設定されます。
  • 散布図シンボル: 散布図シンボルの外観を変更するには、graph->setScatterStyle(…) を呼び出します。可能なすべての散布スタイルについては、QCPScatterStyle のドキュメント、または紹介ページに示されている散布スタイルのデモのスクリーンショットを参照してください。データ ポイントに散布図シンボルを表示したくない場合は、プロットの散布図スタイルを QCPScatterStyle::ssNone に設定します。
列挙型 外観 意味
ssなし 散布図シンボルはプロットされません (例: QCPGraph ではデータは線のみで表されます)
ssドット 単一ピクセル (特定の半径の円が必要な場合は、ssDisc または scircle を使用できます)
ssクロス ここに画像の説明を挿入します 横切って
ssプラス ここに画像の説明を挿入します α+
ssCircle ssCircle.png
ssディスク ssDisc.png ペンの色で塗りつぶされた円(円のようにブラシで塗りつぶされていない)
ssスクエア ssSquare.png 四角
ssダイヤモンド ssダイヤモンド.png ダイヤモンド
ssスター ssStar.png 8 本の腕を持つ星、十字とプラス記号の組み合わせ
ssTriangle ssTriangle.png 基準線に立った正三角形
ssTriangleInverted ssTriangleInverted.png 角に立った正三角形
ssクロススクエア ssクロススクエア.png 十字架のある正方形
ssプラススクエア ssPlusSquare.png 内側にプラス記号がある四角形
ssクロスサークル ssクロスサークル.png 中に十字のある円
ssPlusCircle ssPlusCircle.png 内側にプラス記号が付いた円
ss平和 ss平和.png 1 本の垂直線と 2 本の下向きの対角線を持つ円
ssPixmap setPixmap で指定されたカスタム ピックスマップ (データ ポイント座標を中心とする)
ssカスタム スキャッターごとにカスタム描画操作を実行します (QPainterPath と同様、setCustomPath を参照)
  • グラフの下または 2 つのグラフの間の塗りつぶし: QPainter フレームワークによって提供されるすべてのブラシは、エンティティ、さまざまなパターン、テクスチャ、グラデーション、色、透明度など、グラフの塗りつぶしに使用できます。設定したブラシをgraph->setBrush(…)で設定します。

2. 軸座標軸

軸の描画に使用するペンとラベルに使用するフォントを変更することで、軸の外観を変更できます。QCPAxis のドキュメントを見れば一目瞭然です。最も重要なプロパティの簡単な概要は次のとおりです。

  • セットベースペン、
  • セットティックペン、
  • setTickLength、
  • setSubTickLength、
  • setSubTickPen、
  • setTickLabelフォント、
  • ラベルフォントの設定、
  • setTickLabelPadding、
  • setLabelPadding。

setRangeReversed を使用すると、軸を反転できます (たとえば、値が増加するのではなく、左から右に減少する)。

軸の端に装飾(矢印など)が必要な場合は、setLowerEnding または setUpperEnding を使用します。

3. グリッド

軸の対応する QCPGrid インスタンスにアクセスすることで、グリッドを変更できます。

たとえば、customPlot->yAxis->grid() にアクセスして、左軸にバインドされた水平グリッド線の外観を変更します。グリッド線の外観は基本的にグリッド線が描画される QPen であり、yAxis->grid()->setPen() で設定できます。点 0 のグリッド線は別のペンで描画でき、setZeroLinePen で設定できます。特別なペンでゼロの線を描画したくない場合は、それを Qt::NoPen に設定するだけで、マーク 0 のグリッド線が通常のグリッド ペンで描画されます。
サブグリッド線はデフォルトで非表示に設定されています。これらは、grid()->setSubGridVisible(true) によってアクティブ化できます。

3. ケース

1. 2枚の写真をシンプルにレイアウト

以下は、減衰コサイン関数とその指数包絡線のグラフを作成する例です。

ここに画像の説明を挿入します

// 添加两个图并设置外观:
customPlot->addGraph();
customPlot->graph(0)->setPen(QPen(Qt::blue)); // 第一张图的线条颜色为蓝色
customPlot->graph(0)->setBrush(QBrush(QColor(0, 0, 255, 20))); //第一个Graph将被半透明的蓝色填充
customPlot->addGraph();
customPlot->graph(1)->setPen(QPen(Qt::red)); // 第二张图的线条颜色为红色

// 生成一些数据点(第一张图为y0,第二张图为y1):
QVector<double> x(251), y0(251), y1(251);
for (int i=0; i<251; ++i)
{
    
    
  x[i] = i;
  y0[i] = qExp(-i/150.0)*qCos(i/10.0); // 指数衰减余弦
  y1[i] = qExp(-i/150.0);              // 指数函数
}

// configure right and top axis to show ticks but no labels:
// (see QCPAxisRect::setupFullAxesBox for a quicker method to do this)
customPlot->xAxis2->setVisible(true);
customPlot->xAxis2->setTickLabels(false);
customPlot->yAxis2->setVisible(true);
customPlot->yAxis2->setTickLabels(false);

// make left and bottom axes always transfer their ranges to right and top axes:
connect(customPlot->xAxis, SIGNAL(rangeChanged(QCPRange)), customPlot->xAxis2, SLOT(setRange(QCPRange)));
connect(customPlot->yAxis, SIGNAL(rangeChanged(QCPRange)), customPlot->yAxis2, SLOT(setRange(QCPRange)));

// pass data points to graphs:
customPlot->graph(0)->setData(x, y0);
customPlot->graph(1)->setData(x, y1);

// let the ranges scale themselves so graph 0 fits perfectly in the visible area:
customPlot->graph(0)->rescaleAxes();

// same thing for graph 1, but only enlarge ranges (in case graph 1 is smaller than graph 0):
customPlot->graph(1)->rescaleAxes(true);

// Note: we could have also just called customPlot->rescaleAxes(); instead
// Allow user to drag axis ranges with mouse, zoom with mouse wheel and select graphs by clicking:
customPlot->setInteractions(QCP::iRangeDrag | QCP::iRangeZoom | QCP::iSelectPlottables);

ご覧のとおり、グラフに塗りつぶしを適用することは、Qt::NoBrush ではないブラシを設定するのと同じくらい簡単です。塗りつぶしは、グラフ (ここでは Graph0) から、キー (ここでは x) 軸に平行なゼロ値の線までになります。このグラフと別のグラフの間のチャネルを埋める場合は、さらにgraph->setChannelFillGraph(otherGraph)を呼び出します。チャネルのパディングを削除するには、otherGraph として 0 を渡すだけで、パディングは以前と同様にゼロ値のラインまで進みます。パディングを完全に削除するには、graph->setBrush(Qt::NoBrush) を呼び出します。

2. 複数の軸とより高度なスタイルを使用したプロット

ここで、より複雑な例を見てみましょう。4 軸上の 5 つのグラフ、テクスチャ塗りつぶし、垂直誤差バー、凡例、小数点区切りとしての点などを含むデモ スクリーンショットを作成します。

112

customPlot->setLocale(QLocale(QLocale::English, QLocale::UnitedKingdom)); // period as decimal separator and comma as thousand separator
customPlot->legend->setVisible(true);
QFont legendFont = font();  // start out with MainWindow's font..
legendFont.setPointSize(9); // and make a bit smaller for legend
customPlot->legend->setFont(legendFont);
customPlot->legend->setBrush(QBrush(QColor(255,255,255,230)));
// by default, the legend is in the inset layout of the main axis rect. So this is how we access it to change legend placement:
customPlot->axisRect()->insetLayout()->setInsetAlignment(0, Qt::AlignBottom|Qt::AlignRight);
 
// setup for graph 0: key axis left, value axis bottom
// will contain left maxwell-like function
customPlot->addGraph(customPlot->yAxis, customPlot->xAxis);
customPlot->graph(0)->setPen(QPen(QColor(255, 100, 0)));
customPlot->graph(0)->setBrush(QBrush(QPixmap("./balboa.jpg"))); // fill with texture of specified image
customPlot->graph(0)->setLineStyle(QCPGraph::lsLine);
customPlot->graph(0)->setScatterStyle(QCPScatterStyle(QCPScatterStyle::ssDisc, 5));
customPlot->graph(0)->setName("Left maxwell function");
 
// setup for graph 1: key axis bottom, value axis left (those are the default axes)
// will contain bottom maxwell-like function with error bars
customPlot->addGraph();
customPlot->graph(1)->setPen(QPen(Qt::red));
customPlot->graph(1)->setBrush(QBrush(QPixmap("./balboa.jpg"))); // same fill as we used for graph 0
customPlot->graph(1)->setLineStyle(QCPGraph::lsStepCenter);
customPlot->graph(1)->setScatterStyle(QCPScatterStyle(QCPScatterStyle::ssCircle, Qt::red, Qt::white, 7));
customPlot->graph(1)->setName("Bottom maxwell function");
QCPErrorBars *errorBars = new QCPErrorBars(customPlot->xAxis, customPlot->yAxis);
errorBars->removeFromLegend();
errorBars->setDataPlottable(customPlot->graph(1));
 
// setup for graph 2: key axis top, value axis right
// will contain high frequency sine with low frequency beating:
customPlot->addGraph(customPlot->xAxis2, customPlot->yAxis2);
customPlot->graph(2)->setPen(QPen(Qt::blue));
customPlot->graph(2)->setName("High frequency sine");
 
// setup for graph 3: same axes as graph 2
// will contain low frequency beating envelope of graph 2
customPlot->addGraph(customPlot->xAxis2, customPlot->yAxis2);
QPen blueDotPen;
blueDotPen.setColor(QColor(30, 40, 255, 150));
blueDotPen.setStyle(Qt::DotLine);
blueDotPen.setWidthF(4);
customPlot->graph(3)->setPen(blueDotPen);
customPlot->graph(3)->setName("Sine envelope");
 
// setup for graph 4: key axis right, value axis top
// will contain parabolically distributed data points with some random perturbance
customPlot->addGraph(customPlot->yAxis2, customPlot->xAxis2);
customPlot->graph(4)->setPen(QColor(50, 50, 50, 255));
customPlot->graph(4)->setLineStyle(QCPGraph::lsNone);
customPlot->graph(4)->setScatterStyle(QCPScatterStyle(QCPScatterStyle::ssCircle, 4));
customPlot->graph(4)->setName("Some random data around\na quadratic function");
 
// generate data, just playing with numbers, not much to learn here:
QVector<double> x0(25), y0(25);
QVector<double> x1(15), y1(15), y1err(15);
QVector<double> x2(250), y2(250);
QVector<double> x3(250), y3(250);
QVector<double> x4(250), y4(250);
for (int i=0; i<25; ++i) // data for graph 0
{
    
    
  x0[i] = 3*i/25.0;
  y0[i] = qExp(-x0[i]*x0[i]*0.8)*(x0[i]*x0[i]+x0[i]);
}
for (int i=0; i<15; ++i) // data for graph 1
{
    
    
  x1[i] = 3*i/15.0;;
  y1[i] = qExp(-x1[i]*x1[i])*(x1[i]*x1[i])*2.6;
  y1err[i] = y1[i]*0.25;
}
for (int i=0; i<250; ++i) // data for graphs 2, 3 and 4
{
    
    
  x2[i] = i/250.0*3*M_PI;
  x3[i] = x2[i];
  x4[i] = i/250.0*100-50;
  y2[i] = qSin(x2[i]*12)*qCos(x2[i])*10;
  y3[i] = qCos(x3[i])*10;
  y4[i] = 0.01*x4[i]*x4[i] + 1.5*(rand()/(double)RAND_MAX-0.5) + 1.5*M_PI;
}
 
// pass data points to graphs:
customPlot->graph(0)->setData(x0, y0);
customPlot->graph(1)->setData(x1, y1);
errorBars->setData(y1err);
customPlot->graph(2)->setData(x2, y2);
customPlot->graph(3)->setData(x3, y3);
customPlot->graph(4)->setData(x4, y4);
// activate top and right axes, which are invisible by default:
customPlot->xAxis2->setVisible(true);
customPlot->yAxis2->setVisible(true);
// set ranges appropriate to show data:
customPlot->xAxis->setRange(0, 2.7);
customPlot->yAxis->setRange(0, 2.6);
customPlot->xAxis2->setRange(0, 3.0*M_PI);
customPlot->yAxis2->setRange(-70, 35);
// set pi ticks on top axis:
customPlot->xAxis2->setTicker(QSharedPointer<QCPAxisTickerPi>(new QCPAxisTickerPi));
// add title layout element:
customPlot->plotLayout()->insertRow(0);
customPlot->plotLayout()->addElement(0, 0, new QCPTextElement(customPlot, "Way too many graphs in one plot", QFont("sans", 12, QFont::Bold)));
// set labels:
customPlot->xAxis->setLabel("Bottom axis with outward ticks");
customPlot->yAxis->setLabel("Left axis label");
customPlot->xAxis2->setLabel("Top axis label");
customPlot->yAxis2->setLabel("Right axis label");
// make ticks on bottom axis go outward:
customPlot->xAxis->setTickLength(0, 5);
customPlot->xAxis->setSubTickLength(0, 3);
// make ticks on right axis go inward and outward:
customPlot->yAxis2->setTickLength(3, 3);
customPlot->yAxis2->setSubTickLength(1, 1);

ご覧のとおり、グラフ内でどの軸がどの役割を果たすかを自由に定義できます。たとえば、インデックス 0 のグラフは、左軸 (yAxis) をキーとして使用し、下軸 (xAxis) をその値として使用します。したがって、グラフは左軸に対して上向きになります。

Graph1 の誤差範囲を表示するには、他のプロット テーブル (QCPGraph など) に接続できる QCPErrorBars インスタンスを作成し、それらに誤差範囲を提供します。使用されるメソッドの詳細については、対応するドキュメントを参照してください。

3. 日付と時刻のデータをプロットする

次に、日付や時刻に関連するデータをプロットする方法を見ていきます。基本的には、タイプ QCPAxisTickerDateTime の異なる軸ティックをそれぞれの軸にインストールすることになります。

ここに画像の説明を挿入します

// set locale to english, so we get english month names:
customPlot->setLocale(QLocale(QLocale::English, QLocale::UnitedKingdom));

// seconds of current time, we'll use it as starting point in time for data:
double now = QDateTime::currentDateTime().toTime_t();
srand(8); // set the random seed, so we always get the same random data

// create multiple graphs:
for (int gi=0; gi<5; ++gi)
{
    
    
  customPlot->addGraph();
  QColor color(20+200/4.0*gi,70*(1.6-gi/4.0), 150, 150);
  customPlot->graph()->setLineStyle(QCPGraph::lsLine);
  customPlot->graph()->setPen(QPen(color.lighter(200)));
  customPlot->graph()->setBrush(QBrush(color));
  
  // generate random walk data:
  QVector<QCPGraphData> timeData(250);
  for (int i=0; i<250; ++i)
  {
    
    
    timeData[i].key = now + 24*3600*i;
    if (i == 0)
      timeData[i].value = (i/50.0+1)*(rand()/(double)RAND_MAX-0.5);
    else
      timeData[i].value = qFabs(timeData[i-1].value)*(1+0.02/4.0*(4-gi)) + (i/50.0+1)*(rand()/(double)RAND_MAX-0.5);
  }
  customPlot->graph()->data()->set(timeData);
}

// configure bottom axis to show date instead of number:
QSharedPointer<QCPAxisTickerDateTime> dateTicker(new QCPAxisTickerDateTime);
dateTicker->setDateTimeFormat("d. MMMM\nyyyy");
customPlot->xAxis->setTicker(dateTicker);

// configure left axis text labels:
QSharedPointer<QCPAxisTickerText> textTicker(new QCPAxisTickerText);
textTicker->addTick(10, "a bit\nlow");
textTicker->addTick(50, "quite\nhigh");
customPlot->yAxis->setTicker(textTicker);

// set a more compact font size for bottom and left axis tick labels:
customPlot->xAxis->setTickLabelFont(QFont(QFont().family(), 8));
customPlot->yAxis->setTickLabelFont(QFont(QFont().family(), 8));

// set axis labels:
customPlot->xAxis->setLabel("Date");
customPlot->yAxis->setLabel("Random wobbly lines value");

// make top and right axes visible but without ticks and labels:
customPlot->xAxis2->setVisible(true);
customPlot->yAxis2->setVisible(true);
customPlot->xAxis2->setTicks(false);
customPlot->yAxis2->setTicks(false);
customPlot->xAxis2->setTickLabels(false);
customPlot->yAxis2->setTickLabels(false);

// set axis ranges to show all data:
customPlot->xAxis->setRange(now, now+24*3600*249);
customPlot->yAxis->setRange(0, 60);

// show legend with slightly transparent background brush:
customPlot->legend->setVisible(true);
customPlot->legend->setBrush(QColor(255, 255, 255, 150));

dateTicker->setDateTimeFormat() に渡される文字列には、QDateTime::toString に渡される文字列と同じ日付書式設定オプションがあります。Qt のドキュメントを参照してください。QCustomPlot のすべての日付/時刻座標は、午前 0 時 1 時からの秒数として扱われます。1970 年 1 月、UTC (Unix/エポックタイムとして知られる)。これは、Qt 日付/時刻クラスで QDateTime::toTime_t または setTime_t を呼び出すときに使用する単位でもあります。

1 秒未満の精度を実現するために、軸タイマーは浮動小数点数で動作します。したがって、1.0 未満の値は、対応する秒の小数部分を表します。QCPAxisTickerDateTime::dateTimeToKey と keyToDateTime を使用して、Qt のバージョンに関係なく、浮動小数点の Unix 時刻と QDateTime を変換できます (Qt の QDateTime::toMSecsSinceEpoch は Qt 4.7 でのみ導入されました)。

4. その他のグラフ: 曲線、棒グラフ、統計図など。

ここまではチャートだけを見てきました。これらは主要な使用例であるため、QCustomPlot は専用のインターフェイスを提供します。私たちは常にこれを使用します: QCustomPlot::addGraph、QCustomPlot::graph など。しかし、それだけではありません。QCustomPlot には、Plottable と呼ばれる、プロットにデータをプロットするために使用されるクラス用のより一般的なインターフェイスがあります。

このインターフェイスは、抽象基本クラス QCPAbstractPlottable を中心に構築されています。すべての Plottable は、このクラスとよく知られた QCPGraph クラスから取得されます。QCustomPlot は他にも多くのプロット クラスを提供します。

  • QCPGraph : これは、私たちが使用してきたグラフ化可能なクラスです。一連のデータ ポイントを、さまざまな線種、塗りつぶし、散布点を使用してグラフとして表示します。

  • QCPCurve : QCPGraph に似ていますが、パラメトリック曲線を表示するために使用される点が異なります。関数グラフとは異なり、サイクルがある場合があります。

  • QCPBars : 棒グラフ。一連のデータ ポイントを取得し、それらをバーとして表します。プロット内に複数の qcpbar プロットがある場合は、紹介ページのスクリーンショットに示すように、それらを積み重ねることができます。

  • QCPStatisticalBox : 統計的な箱ひげ図。5 桁の要約 (最小値、下位四分位、中央値、上位四分位、最大値) を取得し、それを統計ボックスとして表します。外れ値も表示できます。

  • QCPColorMap : カラー グラデーションを使用してデータの 3 次元を視覚化する 2D マップ。クラス QCPColorScale は、チャート内のデータのスケールを視覚化するためにこのチャートに付属しています。

  • QCPFinancial : ローソク足または OHLC バーを使用して、株価の始値、高値、安値、終値などの情報を視覚化できるチャート。

  • QCPErrorBars : これは、他のチャートのデータ ポイントにエラーバーを表示できるようにするために 2 番目のチャートにアタッチされるため、特別なチャートです。

QCPGraph とは異なり、他のプロットは QCustomPlot の外部の new を使用して作成する必要がありますこれは、addCurve 関数や addBars 関数はありませんが、addGraph 関数は存在することを意味します。

プロットテーブルが属する QCustomPlot インスタンスは、プロットテーブルのコンストラクターに渡された軸から推測されます。その後、QCustomPlot がプロットテーブルの所有権を取得します。既存のプロットテーブルには QCustomPlot::plottable(int Index) を使用してアクセスでき、グラフ (Graph を含む) 内のプロットテーブルの総数は QCustomPlot::plottableCount を使用して取得できますもちろん、このインデックス関係を維持するために自分でマップを設定することもできます。

3 つのヒストグラムを作成する簡単な例を次に示します。

QCPBars *myBars = new QCPBars(customPlot->xAxis, customPlot->yAxis);
// now we can modify properties of myBars:
myBars->setName("Bars Series 1");
QVector<double> keyData;
QVector<double> valueData;
keyData << 1 << 2 << 3;
valueData << 2 << 4 << 8;
myBars->setData(keyData, valueData);
customPlot->rescaleAxes();
customPlot->replot();

他の図面の詳細については、サンプル プロジェクトや他のチュートリアルを参照してください。さらに、各描画可能タイプについては、それぞれのクラスのドキュメント ページで詳しく説明されています。

もちろん、独自のグラフを作成して、あらゆるデータを必要なとおりに表示することは完全に可能です。サブクラス化を開始する方法については、QCPAbstractPlottable のドキュメントを参照してください。既存のプロットを調べて、それらがどのように機能するかを確認することもできます。

この目的のために、最初に QCPBars または QCPCurve を確認することをお勧めします。QCPGraph は機能が非常に豊富なので、出発点としては適切ではないかもしれません。

おすすめ

転載: blog.csdn.net/qq_43680827/article/details/133444525