Hi Yejin,
I start from the Glass Multi-Bar Chart sample code and I modified a few lines to get the chart in the attached image.
https://www.advsofteng.com/doc/cdcpp.htm#glassmultibar.htm
Basically, I change:
BarLayer* layer = c->addBarLayer(Chart::Side);
layer->addDataSet(DoubleArray(data0, data0_size), 0xff0000, "Server #1");
layer->addDataSet(DoubleArray(data1, data1_size), 0x00ff00, "Server #2");
layer->addDataSet(DoubleArray(data2, data2_size), 0xff8800, "Server #3");
// Set bar border to transparent. Use glass lighting effect with light direction from left.
layer->setBorderColor(Chart::Transparent, Chart::glassEffect(Chart::NormalGlare, Chart::Left));
// Configure the bars within a group to touch each others (no gap)
layer->setBarGap(0.2, Chart::TouchBar);
to:
for (int i = 0; i < data0_size; ++i)
{
BarLayer* layer = c->addBarLayer(Chart::Side);
std::vector<double> oneBar(data0_size, Chart::NoValue);
oneBar[i] = data0[i];
layer->addDataSet(DoubleArray(oneBar.data(), oneBar.size()), -1, "Server #1");
oneBar[i] = data1[i];
layer->addDataSet(DoubleArray(oneBar.data(), oneBar.size()), -1, "Server #2");
oneBar[i] = data2[i];
layer->addDataSet(DoubleArray(oneBar.data(), oneBar.size()), -1, "Server #3");
// Set bar border to transparent. Use glass lighting effect with light direction from left.
layer->setBorderColor(Chart::Transparent, Chart::glassEffect(Chart::NormalGlare, Chart::Left));
// Configure the bars within a group to touch each others (no gap)
layer->setBarGap(0.2, Chart::TouchBar);
}
Basically, the chart contains 5 bar chart layers, with each layer responsible for bars at a certain x position. In this way, all bars can have different colors. (In the code above, I use "-1" as the color, in which case ChartDirector will automatically choose a color.)
Best Regards
Peter Kwan
|