0

I have a QCustomPlot which is graphing incoming data. The plots look great but when I resize the window or zoom or drag abruptly the data get misplotted, as if I dragged a canvas out from under a painter.

Why does this happen? I will be trying to add a condition in my plotting slot to detect if a drag is occurring and hold off the plotting but I wish I didn't have to.

If QCustomPlot has the keys and values, why can't it position them correctly during a replot no matter how the plot has been resized?

AKstat
  • 354
  • 3
  • 14

2 Answers2

0

I had similar issues. I solved it creating a slot "onBeforeReplot( )" which is connected to QQCustomPlot's Signal "beforeReplot()". In the slot, first I obtain the QCustomPlot's pointer:

QCustomPlot *plot = dynamic_cast<QCustomPlot*>(QObject::sender() );

If the pointer is not NULL, the sender is a valid QCustomPlot and you could e.g. write some code like this:

plot->xAxis->setRange( computeValidRangeX( plot->xAxis->range() ) );
plot->yAxis->setRange( computeValidRangeY( plot->xAxis->range() ) );

to ensure the ranges are valid. The methods "computeValidRange*" do have the current range as input and give a valid range. In it you could set minimal or maximal values and a minimum span for the range.

Gombat
  • 1,994
  • 16
  • 21
  • So resetting the range right before replot solved the issue of the points being misplotted and jittery looking, instead of smooth? I'm only asking to clarify because it doesn't seem obvious that would solve the problem. Will try it tonight, thank you. – AKstat Sep 08 '15 at 03:50
  • Maybe you shold clarify the question and add some pictures. Now I'm not sure whether it helps. Did you try it? – Gombat Sep 08 '15 at 07:31
0

This ended up not being a QCustomPlot issue really, which is why it wasn't obvious at first. In my program I am receiving real time data. The data gets timestamped in my add data/replot function. Since replots are queued, when I dragged and resized the plots, it caused a delay in when my add data/replot function got called thus throwing off the time stamp.

I fixed this by creating the timestamp as soon as I have parsed my data, which is managed by a different class. I then pass the timestamp to my add data/replot function.

So if you are using real time data, take your time stamp as early in your program as possible, and don't put it in a function which is likely to get delayed or queued behind other threads.

AKstat
  • 354
  • 3
  • 14