QCustomPlot Discussion and Comments

Is it possible to disable zooming on y-axis but not on x-axisReturn to overview

Hi

I would like to to disable zooming on y-axis but not on x-axis. The effect I'm looking for is the same as that provided by Google finance.

That is: when you zoom in, the y-axis stays the same while the x-axis zooms in. Also, when during RangeDrag operations, is it possible to drag horizontally, but not vertically.

As a bonus: If the above is possible, is it possible to adjust the y-axis If you zoom in on the x-axis and the y-axis automatically adjusts its max and min values depending on what is currently displayed (as in google finance).

Thanks!
Jaco

Hi Jaco,

yes that's all possible, have a look at the documentation of QCPAxisRect, especially the methods setRangeDrag, setRangeZoom, setRangeDragAxes and setRangeZoomAxes. The automatic scaling can be achieved with calling rescaleValueAxis() on the respective graphs, see its documentation for how to use it.

The interactions example also demonstrates many of the things you ask, so you could also find something interesting there.

Hi DerManu

Thanks for the reply. No I was trying to find this functionality in the QCPAxis class. I think I need to get more used to the different parts of the plots :)

Let me have a look and see if I can figure it out. Thanks!
Jaco

Ok, I have to say that was easy. The y-axis locking works with just 2 extra lines of code.

I'm still struggling with two things though:
1) I'm trying to understand how recsaleValueAxis can help me. I've created a slot which I connect to the rangeChanged of my x-axis. In this slot I call rescaleValueAxis() on my plottable but the y-axis stays fixed and does not adjust to the values.
2) Is it possible to easily set the maximum range for the x-axis. The range drag and zoom should not allow the x-axis to move beyond this point (as in google finance again)?

Could you post (or send me) the relevant portions of your code? Especially: Does a replot happen after those range changes? e.g. by explicitly calling replot(), or by the rangeChange happening due to user interaction. And does the plottable contain data points with a value span > 0?

Sure. I subclass QCustomPlot and in my class constructor I do:

connect(xAxis,SIGNAL(rangeChanged(QCPRange)),SLOT(xAxisScaleChanged()));

In the xAxisScaleChanged() slot I just call rescaleValueAxis() on the QCPBars plottable which is the only plottable in my plot.

To answer your questions:
1) I only repolot() manually when the data changes. The range change happens due to a drag or zoom operation yes.
2) Yes, the plot contains only positive values (if I understand your question correctly).

I am trying to make the same thing as you. Is it possible to easily set the maximum range for the x-axis. The range drag and zoom should not allow the x-axis to move beyond this point (as in google finance again)?

Here is the answer. http://www.qcustomplot.com/index.php/support/forum/289

Thanks