How do I specify the bar colors in ImPlot::DrawBarGroups?

528 Views Asked by At

I'm struggling to understand how the colors work in ImPlot.

Here, I'm plotting bars in groups of 3.

static const char* labels[] = {"X", "Y", "Z"};
if (ImPlot::BeginPlot("Sensor activity"))
{
    ImPlot::PlotBarGroups(labels, &(barData[0]), 3, numGroups, 1.0f, 0, 0);
    ImPlot::EndPlot();
}

I would like the X, Y, and Z bars to be plotted in Red, Green and Blue respectively. How would I do that?

1

There are 1 best solutions below

0
On BEST ANSWER

You should be able to add your own colormap, first setup your colormap like this (only do it once):

static ImU32 colorDataRGB[3] = { 0xFFFF0000, 0xFF00FF00, 0xFF0000FF };
int customRGBMap = ImPlot::AddColormap("RGBColors", colorDataRGB, 32);

And then

ImPlot::PushColorMap(customRGBMap);
ImPlot::BeginPlot(...);
...
ImPlot::EndPlot();
ImPlot::PopColorMap();