Problem adding data from Array with TBar3DSeries

TeeChart VCL for Borland/CodeGear/Embarcadero RAD Studio, Delphi and C++ Builder.
Post Reply
Metman
Advanced
Posts: 113
Joined: Fri Dec 21, 2007 12:00 am

Problem adding data from Array with TBar3DSeries

Post by Metman » Thu Feb 21, 2013 5:28 pm

Hi

I am using the example from your documentation to add values from a dynamic array directly to a TBar3DSeries like this:

Code: Select all

with Series1.XValues do
begin
  Value:=TChartValues(x);
  Count:=length(x);
  Modified:=True;
end;

with Series1.YValues do
begin
   Value:=TChartValues(y);
   Count:=length(y);
   Modified:=True;
end;

Series1.Repaint;
It throws an exception when I try it. If I change the series to anything else - a line series perhaps - it works fine with exactly the same data. Is there something special about a TBar3Dseries that I'm missing or is it a bug??

Bruce.

Narcís
Site Admin
Site Admin
Posts: 14730
Joined: Mon Jun 09, 2003 4:00 am
Location: Banyoles, Catalonia
Contact:

Re: Problem adding data from Array with TBar3DSeries

Post by Narcís » Mon Feb 25, 2013 11:04 am

Hi Bruce,

This is because you need to provide OffsetValues for this series style, for example:

Code: Select all

procedure TForm1.FormCreate(Sender: TObject);
Var X,Y,O   : Array of Double;   // TChartValues
    t       : Integer;
    Num     : Integer;
begin
  { 100 points }
  Num:= 100;

  { allocate our custom arrays }
  SetLength(X,Num);
  SetLength(Y,Num);
  SetLength(O,Num);

  { fill data in our custom arrays }
  X[0]:=0;
  Y[0]:=Random(10000);
  O[0]:=Random(1000);
  for t:=1 to Num-1 do
  begin
    X[t]:=t;
    Y[t]:=Y[t-1]+Random(101)-50;
    O[t]:=Y[t-1]+Random(1000)-500;
  end;

  with Series1.XValues do
  begin
    Value:=TChartValues(x);
    Count:=length(x);
    Modified:=True;
  end;

  with Series1.YValues do
  begin
     Value:=TChartValues(y);
     Count:=length(y);
     Modified:=True;
  end;

  with Series1.OffsetValues do
  begin
     Value:=TChartValues(O);
     Count:=length(O);
     Modified:=True;
  end;

  Series1.Repaint;
end;
Best Regards,
Narcís Calvet / Development & Support
Steema Software
Avinguda Montilivi 33, 17003 Girona, Catalonia
Tel: 34 972 218 797
http://www.steema.com
Image Image Image Image Image Image
Instructions - How to post in this forum

Metman
Advanced
Posts: 113
Joined: Fri Dec 21, 2007 12:00 am

Re: Problem adding data from Array with TBar3DSeries

Post by Metman » Mon Feb 25, 2013 11:54 am

Narcis

Thanks for the code - my 3D Bar chart now works - it's so much faster adding an array than adding each point!

Now one final question that is probably not possible but here goes -

Is it possible to assign a color to each of the bars like you do with the offset?

I've looked and can't find a corresponding list to set the color - maybe the best way is to set the color as the chart is drawn?

Do you have any suggestion - I want to color bars with a min value above zero red and ones with a min value below zero blue...

Bruce.

Narcís
Site Admin
Site Admin
Posts: 14730
Joined: Mon Jun 09, 2003 4:00 am
Location: Banyoles, Catalonia
Contact:

Re: Problem adding data from Array with TBar3DSeries

Post by Narcís » Mon Feb 25, 2013 1:01 pm

Hi Bruce,
I've looked and can't find a corresponding list to set the color - maybe the best way is to set the color as the chart is drawn?
Not exactly, you need to do this:

Code: Select all

procedure TForm1.FormCreate(Sender: TObject);
Var X,Y,O   : Array of Double;   // TChartValues
    C       : Array of TColor;
    t       : Integer;
    Num     : Integer;
begin
  { 100 points }
  Num:= 100;

  { allocate our custom arrays }
  SetLength(X,Num);
  SetLength(Y,Num);
  SetLength(O,Num);
  SetLength(C,Num);

  { fill data in our custom arrays }
  X[0]:=0;
  Y[0]:=Random(10000);
  O[0]:=Random(1000);
  C[0]:=RGB(Random(255),Random(255),Random(255));
  for t:=1 to Num-1 do
  begin
    X[t]:=t;
    Y[t]:=Y[t-1]+Random(101)-50;
    O[t]:=Y[t-1]+Random(1000)-500;
    C[t]:=RGB(Random(255),Random(255),Random(255));
  end;

  with Series1.XValues do
  begin
    Value:=TChartValues(x);
    Count:=length(x);
    Modified:=True;
  end;

  with Series1.YValues do
  begin
     Value:=TChartValues(y);
     Count:=length(y);
     Modified:=True;
  end;

  with Series1.OffsetValues do
  begin
     Value:=TChartValues(O);
     Count:=length(O);
     Modified:=True;
  end;

  for t:=0 to Series1.Count-1 do
    Series1.ValueColor[t]:=C[t];

  Series1.Repaint;
end;
Do you have any suggestion - I want to color bars with a min value above zero red and ones with a min value below zero blue...
Ok, in that case it could be:

Code: Select all

procedure TForm1.FormCreate(Sender: TObject);
Var X,Y,O   : Array of Double;   // TChartValues
    t       : Integer;
    Num     : Integer;
    tmp     : Double;
begin
  { 100 points }
  Num:= 100;

  { allocate our custom arrays }
  SetLength(X,Num);
  SetLength(Y,Num);
  SetLength(O,Num);

  { fill data in our custom arrays }
  X[0]:=0;
  Y[0]:=Random(10000);
  O[0]:=Random(1000);

  for t:=1 to Num-1 do
  begin
    X[t]:=t;
    Y[t]:=Y[t-1]+Random(101)-50;
    O[t]:=Y[t-1]+Random(1000)-500;
  end;

  with Series1.XValues do
  begin
    Value:=TChartValues(x);
    Count:=length(x);
    Modified:=True;
  end;

  with Series1.YValues do
  begin
     Value:=TChartValues(y);
     Count:=length(y);
     Modified:=True;
  end;

  with Series1.OffsetValues do
  begin
     Value:=TChartValues(O);
     Count:=length(O);
     Modified:=True;
  end;

  for t:=0 to Series1.Count-1 do
  begin
    tmp:=Y[t]+O[t];
    if tmp > 0 then
      Series1.ValueColor[t]:=clRed
    else
      Series1.ValueColor[t]:=clBlue;
  end;

  Series1.Repaint;
end;
Best Regards,
Narcís Calvet / Development & Support
Steema Software
Avinguda Montilivi 33, 17003 Girona, Catalonia
Tel: 34 972 218 797
http://www.steema.com
Image Image Image Image Image Image
Instructions - How to post in this forum

Metman
Advanced
Posts: 113
Joined: Fri Dec 21, 2007 12:00 am

Re: Problem adding data from Array with TBar3DSeries

Post by Metman » Mon Feb 25, 2013 2:34 pm

Narcis

That's great and works fine - just one last thing!

When I use the mouse to scroll the chart I notice that there is more often than not a gap of missing bars against the extreme left hand side of the chart. This doesn't happen on the right hand side of the chart and I wondered if you could look at this Flash movie I've put together to try and show you what I mean.

http://www.xmetman.co.uk/images/GFS%20Viewer1.swf

If you do the scroll slowly it always misses bars sometimes if you do it quickly it draws them all fine!
I have a lot of values in the chart - they are daily from 1850 so they're about (365*150) 54,750 of them.

I'd appreciate your advice on what's going on.

Bruce.

Narcís
Site Admin
Site Admin
Posts: 14730
Joined: Mon Jun 09, 2003 4:00 am
Location: Banyoles, Catalonia
Contact:

Re: Problem adding data from Array with TBar3DSeries

Post by Narcís » Mon Feb 25, 2013 2:51 pm

Hi Bruce,

You're welcome.
When I use the mouse to scroll the chart I notice that there is more often than not a gap of missing bars against the extreme left hand side of the chart.
Could you please attach a simple example project we can run "as-is" to reproduce the problem here?

Thanks in advance.
Best Regards,
Narcís Calvet / Development & Support
Steema Software
Avinguda Montilivi 33, 17003 Girona, Catalonia
Tel: 34 972 218 797
http://www.steema.com
Image Image Image Image Image Image
Instructions - How to post in this forum

Metman
Advanced
Posts: 113
Joined: Fri Dec 21, 2007 12:00 am

Re: Problem adding data from Array with TBar3DSeries

Post by Metman » Mon Feb 25, 2013 3:34 pm

Narcis

Won't be easy but I'll try!

Bruce.

Metman
Advanced
Posts: 113
Joined: Fri Dec 21, 2007 12:00 am

Re: Problem adding data from Array with TBar3DSeries

Post by Metman » Tue Feb 26, 2013 8:25 am

Narcis

Did you get my test project or should I resend it?

Bruce.

Narcís
Site Admin
Site Admin
Posts: 14730
Joined: Mon Jun 09, 2003 4:00 am
Location: Banyoles, Catalonia
Contact:

Re: Problem adding data from Array with TBar3DSeries

Post by Narcís » Tue Feb 26, 2013 8:36 am

Hi Bruce,

No, I didn't. Sorry. Where did you send it? You may resend it at http://www.steema.net/upload/.

Thanks in advance.
Best Regards,
Narcís Calvet / Development & Support
Steema Software
Avinguda Montilivi 33, 17003 Girona, Catalonia
Tel: 34 972 218 797
http://www.steema.com
Image Image Image Image Image Image
Instructions - How to post in this forum

Metman
Advanced
Posts: 113
Joined: Fri Dec 21, 2007 12:00 am

Re: Problem adding data from Array with TBar3DSeries

Post by Metman » Tue Feb 26, 2013 11:00 am

Narcis

I've just seen the problem - there is a 56 offset on the bottom axis for some reason!

Bruce.

Post Reply