QCustomPlot Discussion and Comments

unique bar colorsReturn to overview

Hello everyone,

I am trying to create a bargraph with 37 bars that switches based on the input value. However I can not find a simple way of doing this. Here is my attempt loop at trying to switch colors.

for(int i=0; i < 37; i++) {
        if(masterData[i] < 50 && masterData[i] > 20) {
            mGraph->setPen(QPen(QColor(238, 244, 66).lighter(170)));
            mGraph->setBrush(QColor(238, 244, 66));
        } if (masterData[i] < 20) {
            mGraph->setPen(QPen(QColor(244, 65, 65).lighter(170)));
            mGraph->setBrush(QColor(244, 65, 65));
        } else {
            mGraph->setPen(QPen(QColor(73, 244, 65).lighter(170)));
            mGraph->setBrush(QColor(73, 244, 65));
        }
    }

obviously this does not work as it switch all of the bars color and not the individual bar. Any ideas?

so, the color doesnt do anything until the paint event, so of course this would just switch the entire bar plot color.
if you want different colors, they need to be different QCPBars. If you want them to be stacked together, you can use QCPBarsGroup.

you could also subclass QCPBars and override the draw method.