QCustomPlot Discussion and Comments

Unique color per bar in a BarChart?Return to overview

I need to report simple Success vs Failure (ie the value is or is not within max or min boundaries) using green and red for the bars in a bar chart, as this allows me to quickly compare a set of values. How can this be done? I dont see an obvious way to set the color for each value. I can determine the color in my code, just need to set each bar with the color I need.

If you don't want to subclass QCPBars to allow individual bar colors, you could just create one QCPBars plottable for each color that's needed (or for every single bar, if that's easier). Of course that's not the nicest method but can certainly work if some code is used to handle all those bars properly.
The cleanest solution is to indeed subclass QCPBars, add a QColor to QCPBarData and modify the draw methods to draw the bars with their individual color.

can you please give an example how to add Qcolor to QCPBarData, as it holds only double values. and hot to add the QCPBarData to the specific QCPBars

Is there an example code to paint bars of different colors?