|
qcustomplot |
Posted by Mrx Rch on Jun-11-2017 03:40 |
|
Is it possible to show a chartdir chart inside of a qcustomplot (http://qcustomplot.com) widget, so the zoom, drag and other options remains?
(I would like to show indicators inside of it - is it possible?) |
Re: qcustomplot |
Posted by Peter Kwan on Jun-13-2017 05:42 |
|
Hi Mrx,
I think it is possible to "show" one Qt widget inside another Qt widget. This should be a standard Qt feature. In this simplest case, you can just create a Qt Widget with the QCustomPlot as the parent, and the Qt Widget will be "shown" inside the QCustomPlot.
For example:
QCustomPlot *myContainer = new QCustomPlot();
QChartViewer *viewer = new QChartViewer(myContainer);
... create chart and put it in the QChartViewer as usual ....
Note that the above means using the QCustomPlot as a container. So I wonder why don't you just use a QFrame as the container.
Or do you mean you want the ChartDirector zooming, scrolling, viewport control, track cursor and other features to be applied to the QCustomPlot chart? ChartDirector interactive features can only work with ChartDirector charts. You can display the ChartDirector charts inside another Qt Widget as a container, and QCustomPlot can act as a container.
Regards
Peter Kwan |
Re: qcustomplot |
Posted by Mrx Rch on Jun-15-2017 03:43 |
|
Hello Peter,
first of all, many thanks for your answer.
yes, I did exactly what you wrote:
FinanceChart *m = new FinanceChart(1000);
m->addBarIndicator(100, DoubleArray(_data, _data_len), 1, "x");
QChartViewer *m_cv = new QChartViewer(ui->customPlot2);
m->addPlotAreaTitle(Chart::BottomCenter, "test");
m_cv->setChart(m);
So, what I expected, when I zoom or scroll the ui->customPlot2 (which is a QCustomPlot) then it will affect the QChartViewer, but this is not the case. (The chart appears inside the qCustomPlot, but it remains no affected at all - when I resize or scroll / zoom the QChartViewer remains unaffected; however the QCustomPlotis zooming / resizing / etc).
So it seems that these are specific to QCustomPlot and will not affect automatically the elements inside of it. (my apologize, but I'm completely newbie in this Qt, so I guess I don't understand some basic concepts).
The only things I wnated to use QCustomPlot is because of the resizing / scrolling abilities when are easily defined:
ui->customPlot2->setInteraction(QCP::iRangeZoom);
ui->customPlot2->setInteraction(QCP::iRangeDrag);
ui->customPlot2->axisRect()->setRangeDrag(Qt::Horizontal); // Enable only drag along the horizontal axis
ui->customPlot2->axisRect()->setRangeZoom(Qt::Horizontal); // Enable zoom only on the horizontal axis
And when I resize the main window the whole container resizes nicely.
Is this easy to do in chartdir as well? Can you direct me to some examples? Or is there a way to make ChartDir to work together with QCustomPlot?
thanks,
Rch |
Re: qcustomplot |
Posted by Peter Kwan on Jun-16-2017 02:51 |
|
Hi Mrx,
I am not familiar with qcustomplot, but I would guess qcustomplot can only zoom or scroll a chart created with qcustomplot. To make qcustomplot zoom or scroll other things, you would need to modify qcustomplot.
ChartDirector itself has built-in zooming and scrolling support. There are quite a number of zooming and scrolling sample code included in the ChartDirector distribution. See:
http://www.advsofteng.com/doc/cdcpp.htm#zoomscrollintroqt.htm
(At the bottom of the above page, there are links to 6 zooming and scrolling sample code.)
There are also some extra sample code located at:
http://www.advsofteng.com/tutorials/extra.html
If you search this forum for "FinanceChart zoom", there will be a number of post with some code fragments or examples. However, the example is not necessarily in Qt/C++ as ChartDirector supports many programming languages and frameworks. The following is a Qt one that I found:
http://www.chartdir.com/forum/download_thread.php?bn=chartdir_support&thread=1467686966#N1467786759
For resizing a chart based on the container size, you just need to create the chart based on the size of the container, instead of hard coding the size. When the contain change size, in the "resize" event of the container, just redraw the chart. (Call "m_ChartViewer->updateViewPort(true, true);" if it is using the zooming and scrolling framework.) The last example of the "extra sample code" mentioned above is a chart that resizes to the window size.
Hope this can help.
Regards
Peter Kwan |
|