The color of line doesnot change

TeeChart for Microsoft Visual Studio .NET, Xamarin Studio (Android, iOS & Forms) & Monodevelop.
Post Reply
trimble
Newbie
Newbie
Posts: 11
Joined: Mon Dec 14, 2009 12:00 am

The color of line doesnot change

Post by trimble » Thu Jun 17, 2010 12:38 pm

Hello ,

I am facing a small problem , I am creating lines programmtically and want to have each line different color , but what actullay happening is that all lines have the same color, so can some help me, following is the code.

regrads
Trimble

-----------------------------------------------------------------------------------------------------------

void UpdateChart()
{



tChart1.Series.Clear();
byte color_value=255;



foreach (int i in dic.Keys )
{
byte[] bytes = new byte[4];

Random r = new Random();
r.NextBytes(bytes);

List<Cala> ex = dic.ToList();

Steema.TeeChart.Silverlight.Styles.Line line = new Steema.TeeChart.Silverlight.Styles.Line();
Color color = new Color();
int a = (byte)color_value << 5;
int b = (byte)color_value << 3;
int c = (byte)color_value >> 3;
int d = (byte)color_value >> 2;
color = Color.FromArgb((byte)a,(byte)b,(byte)c,(byte)d);
line.Color = color;



foreach (Cala e in ex)
{

line.Add(e.azi, e.elev);
//series.Add(line);
}

tChart1.Series.Add(line);



}

Yeray
Site Admin
Site Admin
Posts: 9612
Joined: Tue Dec 05, 2006 12:00 am
Location: Girona, Catalonia
Contact:

Re: The color of line doesnot change

Post by Yeray » Fri Jun 18, 2010 3:55 pm

Hi Trimble,

Try declaring your Random r out of the for loop. The Randoms are "false randoms" as they always return the same sequence of numbers for a given seed. So, since you are creating a new instance of you random object everytime, the sequence restarts and always give the same value.
Best Regards,
ImageYeray Alonso
Development & Support
Steema Software
Av. Montilivi 33, 17003 Girona, Catalonia (SP)
Image Image Image Image Image Image Please read our Bug Fixing Policy

Post Reply