|
Run Chart - Random Colors for Scatter Trend |
Posted by Joe on Feb-27-2014 03:28 |
|
Hello,
I have a Run Chart, where inside a for loop, I will add a line layer using the following, to generate different trends as I cycle through my data.
for(x=0;x<10;x++)
{
LineLayer1.addDataSet(ScatterJobTrend, 0xCC0000, JobLabel).setDataSymbol(Chart.Cross2Shape(0.4), 15);
}
How to get this to just generate a random color each time, instead of the Red I passed? |
Re: Run Chart - Random Colors for Scatter Trend |
Posted by Peter Kwan on Feb-27-2014 17:07 |
|
Hi Joe,
If you want to use "random colors", please use a random number within the color space
0x000000 to 0xFFFFFF as the color. For example, in C#:
Random r = new Random();
for(x=0;x<10;x++)
{
LineLayer1.addDataSet(ScatterJobTrend, r.Next(0x000000, 0xFFFFFF), JobLabel).
setDataSymbol(Chart.Cross2Shape(0.4), 15);
}
I suggest you use "automatic colors" instead of "random colors". An automatic color is a
color selected from a carefully chosen palette to maximize contrast. If you use random
colors, it is possible the colors can be very similar (because they are random, anything is
possible). To use automatic colors, please use -1 as the color.
Note that the palette in automatic colors are finite in size. The default palette only has 32
unique colors and will recycle them if you use more than 32 automatic colors. You may
extend or redefine the palette using BaseChart.setColors2.
Hope this can help.
Regards
Peter Kwan |
Re: Run Chart - Random Colors for Scatter Trend |
Posted by Joe on Mar-14-2014 01:08 |
|
Thank you this worked perfectly. Is there a way to have random chart symbols generated instead of the Cross Share I have listed for each iteration of the loop? |
Re: Run Chart - Random Colors for Scatter Trend |
Posted by Peter Kwan on Mar-14-2014 02:00 |
|
Hi Joe,
ChartDirector supports infinite variety of shapes. You can create an array containing a list
of shapes you want to use. Then in the loop, you just choose a "random" element from the
array (generate a random integer modulo the array size, and use it as the array index). The
"Built-In Symbols" sample code has an array of symbols for your reference.
From experience, "random" colors or shapes are not good, because you can have exactly
the same symbol (two "random" number can happen to be the same). Instead of "random"
shapes, I suggest you may simply use the loop index modulo the array size as the index to
get the symbols sequentially in a round robin fashion. You can create the symbols array so
that adjacent symbols would look quite different.
Hope this can help.
Regards
Peter Kwan |
|