QCustomPlot Discussion and Comments

How to make QCPBars bars individually selectable?Return to overview

I want the plot to have many-many bars, and each of them individually selectable.

Currently I just create many QCPBars instances, each with only one data point, but this seems not scalable...

Individual data point selectability is currently not possible without own work. For exmaple, you could use the QCPItemRects to indicate selected bars. Or you could create one bars plottable for the unselected and one for the selected bars. The selection can be done with the mouse signals that QCustomPlot emits.

Is it possible to select individual bars and get coordinate values in current version ?
If so kindly provide how to dk that.
Thanks

Yes, individual data point (or multiple data points) selection is possible since 2.0!
Have a look at the data selection mechanism documentation page.

If the data selection of a plottable (e.g. QCPBars) changes, it emits the signal selectionChanged(const QCPDataSelection &selection). The selection parameter contains the current selection, e.g. the clicked bar index, or range of bars, if you allow for range selection.

Getting further key/value or screen pixel coordinates of data points is achieved easily via the 1D data interface: you can simply read out its key and value like so:

double key = bars->dataMainKey(index);
double value = bars->dataMainValue(index);

or get the pixel position on screen like so (this includes any offsets specific to the plottable, as is the case for stacked bars for example, which you wouldn't get by just transforming the above key/value to screen coordinates using QCPAxis::coordToPixel):

QPointF pixelPos = bars->dataPixelPosition(index);