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

Message ListMessage List     Post MessagePost Message

  Bar chart multiple inter-mark color zones/color bars between marks
Posted by Cody on Feb-11-2016 01:39
Attachments:
Hello,

I've got another one. I am trying to find a way to color the bars green between the red
lines in each "group." The marks are generated sequentially from an array that is not
always the same (data is read in from somewhere). I am able to color the bars if I color
the data set using hard values with an xZoneColor, but those values can obviously change.

As before any help would be appreciated

Thanks again,
Cody
EmptyZone.jpg

  Re: Bar chart multiple inter-mark color zones/color bars between marks
Posted by Peter Kwan on Feb-12-2016 01:55
Hi Cody,

The easiest method I can think of is to use two data sets, one for the green bars, one
for the other bars. It should be easy to create such data sets.

For example, suppose your existing bars are contained in a barData array, and the red
line groups are contained in two arrays startValues and endValues, which are the
starting and ending values of the group. The code is then like:

// The greenData array, initialized to Chart.NoValue
double[] greenData = new double[barData.Length];
for (int i = 0; i < greenData.Length; ++i) greenData[i] = Chart.NoValue;

// Move the green bars from the barData array to the greenData array
for (int i = 0; i < startValues.Length; ++i) {
    for (int j = startValues[i]; j <= endValues[i]; ++j) {
         greenData[j] = barData[j];
         barData[j] = Chart.NoValue;
    }
}

Now with the barData and greenData arrays, you can add two bar layers to the chart, or
you can add one bar layer with two data sets, using the Chart.Overlay data combine
method.

**** Note: The above code assumes the x-coordinate is the array index (that is, no
**** Layer.setXData is used), and the startValues and endValues contains the array
**** index of the positions of the mark lines. If the startValues and endValues are
**** floating point numbers or non-integers, you may need to use Math.Floor or
**** Math.Ceiling and cast them into integers.

Hope this can help.

Regards
Peter Kwan

  Re: Bar chart multiple inter-mark color zones/color bars between marks
Posted by Cody on Feb-12-2016 03:19
Peter,

That pointed me in the right direction. I ended up using an array of ints to set the colors
of each bar individually, checking to see if each one was in a target area.

The code is in C++:

int colors[NUM_LEN_COUNTS];//600

for (int i = 0; i < sizeof(colors)/sizeof(colors[0]); ++i)
{
     colors[i] = 0x6699bb;
     for (int j = 0; j < sizeof(targetLengths/sizeof(targetLengths[0]); ++j)
     {
          if (i >= (minLengths[j] * BIN_PER_FOOT) - (MIN_LEN_BRD * BIN_PER_FOOT)
             && i <= (maxLengths[j] * BIN_PER_FOOT) - (MIN_LEN_BRD *
             BIN_PER_FOOT))
          {
               colors[i] = GREEN; //0x00CC00
          }
     }
}

// Draw the histogram
BarLayer *histogramLayer = cHistogram->addBarLayer(DoubleArray(frequency,
(int)(sizeof(frequency)/sizeof(frequency[0]))), IntArray(colors, (int)(sizeof(colors)/
sizeof(colors[0]))));

Thanks again for all the help, it is greatly appreciated.