QCustomPlot Discussion and Comments

problem with QCPLayerReturn to overview

hi, i want to plot a big and online data. the replot delay increase when plot Advanced in screen. for resolving this problem, i am trying to put each 10 ms data in a separate layer and only replot that layer.
i am trying this:

    QCPLayer *main_layer=new QCPLayer(ui->platform, "ms_0");
    QCPLayer *layer=new QCPLayer(ui->platform, "ms_1");
    ui->platform->addLayer("ms_1",main_layer,QCustomPlot::limAbove) ;

but the program crashes.
what is the problem?

2 things: 1 i dont see you creating the graph(0).
2. the layers dont exactly work that way. you add a graph to a specific layer, not add data to a layer on the same graph.

thanks Ian. your first note is noticed. but before your second notice, a problem existed:

    bool check=ui->platform->addLayer("ms_1",main_layer,QCustomPlot::limAbove) ;

i debug the program and see that the bool Check is false. it means:
i cant solve this and i cant find any good example of layering.

i forget to say that my program crashes when in line 13(replot). debugger stops at this line of qcustomplot.cpp:

  if (mMode == lmBuffered && !mParentPlot->hasInvalidatedPaintBuffers()){

As the documentation of QCPLayer says
you must not create layers directly in this way.

You should use the correct interface of QCustomPlot::addLayer

Here's the full description how layers work:

thanks Isso. the second link is very very helpful and illuminator. i change my test code in this way:

    QCPLayer *secon_layer=new QCPLayer(ui->platform, "ms_1");
    bool mq1=ui->platform->addLayer("ms_1",0,QCustomPlot::limAbove) ;
    double a1=0; double  b1=-10;

Due to the second Doc the code set "ms_1" above the other layers. it created successfully(mq1 is true) . with replot the lmBuffered layer (ms_1) only this layer should be replotted. but all of data is plot. why?
NOTE: is line 5 true? it should set the current layer to default main layer.

again, like i pointed out earlier, data isnt added to a specific layer... it is added to the graph. you set the current layer after creating the graph.

your code simplified is as follows:
create graph 0
create a second layer
add data to graph 0
add data to graph 0
add data to graph 0
add data to graph 0
replot layer ms_1.

the problem with this is that you have no data on layer ms_1... your only data is on the main layer, because that's the layer you created graph(0) on. you cant have data points from a graph on two separate layers, that's not how it works.

thanks, that's work. only pay attention that it should be replot platform once after creating graphs on different layers. otherwise it does not work.