0
我正在嘗試使用QCandlestickSeries
和QBarSeries
創建財務股票圖表(價格和數量)。如何在同一個QChart上添加QCandlestickSeries和QBarSeries
但我堅持這個問題 - 我怎麼能在同一張圖上添加兩個系列?
代碼:
...
QChart *pChart = new QChart;
QCandlestickSeries *pPriceSeries = new QCandlestickSeries;
QBarSeries *pVolumeSeries = new QBarSeries;
QBarSet *pVolumeSet = new QBarSet("Volume");
QList<qreal> listVolume;
QDateTimeAxis *pAxisX = new QDateTimeAxis;
QValueAxis *pAxisY = new QValueAxis;
while (!pFile.atEnd())
{
...
// Parsing a file with stock data line by line
// dOpen, dHigh, dLow and dClose - stock price
// dVolume - volume
// dt - date and time
// nSeconds - number of seconds depending of interval (1/5/10 minutes, Day, Week, Month)
...
// Setting ranges to date and time axis, X
// one interval is left/right margin
if (pAxisX->max() < dt) pAxisX->setMax(dt.addSecs(nSeconds));
if (pAxisX->min() > dt || pAxisX->min().toUTC().toSecsSinceEpoch() == 0)
pAxisX->setMin(dt.addSecs(-nSeconds));
// Setting ranges to value axis, Y
// 50px is top/bottom margin
if (pAxisY->max() < dHigh) pAxisY->setMax(dHigh + 50.0);
if (pAxisY->min() > dLow || pAxisY->min() == 0.0)
pAxisY->setMin(dLow - 50.0);
// Create new price candlestick
QCandlestickSet *pPriceSet = new QCandlestickSet(dOpen, dHigh, dLow, dClose, dt.toMSecsSinceEpoch());
pPriceSeries->append(pPriceSet);
// Append volume value to the list
// for example: 568 000/10 000 = 56.8
listVolume.append(dVolume/10000.0);
}
// Add price series to chart
pChart->addSeries(pPriceSeries);
// Fill in the volume set from the list
for (qint64 nVolume = 0; nVolume < listVolume.size(); nVolume++)
// For example: 56.8 + 2887.0 = 2943.8
pVolumeSet->append(listVolume.at(nVolume) + pAxisY->min());
// Add volume series to chart
pVolumeSeries->append(pVolumeSet);
pChart->addSeries(pVolumeSeries);
// Set chart axis X
pChart->setAxisX(pAxisX, pPriceSeries);
pChart->setAxisX(pAxisX, pVolumeSeries);
// Set chart axis Y
pChart->setAxisY(pAxisY, pPriceSeries);
pChart->setAxisY(pAxisY, pVolumeSeries);
...
至於價格燭臺 - 一切正常,但我無法看到圖上的音量條(但傳說是可見的!),我不知道爲什麼...
我在做什麼錯?感謝您提前回答。