ASE Home Page Products Download Purchase Support About ASE
ChartDirector Support
Forum HomeForum Home   SearchSearch

Message ListMessage List     Post MessagePost Message

  multi-color dataset
Posted by Yejin on Dec-21-2022 15:50
Attachments:
I added one BarLayer on XYChart and added two DataSets.

I want to set a different color for each bar. (Chart located above the image. I use "addBarLayer" temporarily.)

But the result came out like the chart located at the bottom of the image when I use "addDataSet" twice.

I think it's because "addDataSet" doesn't support IntArray parameter on color arguments.

Is there any way to make multi-color dataset?
test.png

  Re: multi-color dataset
Posted by Peter Kwan on Dec-22-2022 00:36
Attachments:
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
multicolor_multibar.png