LoadChartFromStream / SaveChartToStream

TeeChart VCL for Borland/CodeGear/Embarcadero RAD Studio, Delphi and C++ Builder.
Post Reply
srdjos
Newbie
Newbie
Posts: 3
Joined: Tue Aug 07, 2007 12:00 am

LoadChartFromStream / SaveChartToStream

Post by srdjos » Tue Nov 04, 2008 12:55 pm

Hi

i'll be very grateful if somebody can explain to me one behaviour of TDBChart

For saving DBChart to database, we are using following statement:

Code: Select all

 SaveChartToStream(TDBChart(chChart), AStream, True, True);
Later we are loading it over:

Code: Select all

 LoadChartFromStream(TCustomChart(chChart), ChartStream);
what's wrong:

let's say we have 3 charts,
first one does not have x axis inverted
second one has it
third one does not have x axis inverted

when first one is loaded, everything is ok
second one also

and, problem is, after loading third one,
inverted property is remebered and x axis on third chart
became inverted, wich means no good

it is not just inverted property
this is happening in all cases when one loaded chart has
plenty of extra properties and following chart does not have it

is this behaviour ok or not

Thanx
Srdjan

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

Post by Narcís » Tue Nov 04, 2008 3:23 pm

Hi Srdjan,

You can try clearing a chart before importing another one like this:

Code: Select all

procedure TForm1.Button1Click(Sender: TObject);
begin
  ClearChart(Chart1);
end;

procedure TForm1.ClearChart(Chart: TChart);
var tmpChart:TChart;
    i: Integer;
begin
  for i:=0 to Chart.SeriesCount-1 do
    if Assigned(TChartSeries(Chart.Series[i]).Datasource) then
      {$IFDEF DATABASE}
      if (TChartSeries(Chart.Series[i]).DataSource is TTeeADOQuery) then
         TChartSeries(Chart.Series[i]).Datasource.Free
      else
      {$ENDIF}
        TChartSeries(Chart.Series[i]).Datasource:=nil;

  Chart.FreeAllSeries;
  Chart.Tools.Clear;
  tmpChart:=TChart.Create(nil);
  try
    tmpChart.Parent:=Chart.Parent;
    Chart.Assign(tmpChart);
  finally
    tmpChart.Free;
  end;
end;
Hope this helps!
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

Achim
Newbie
Newbie
Posts: 10
Joined: Tue Nov 27, 2007 12:00 am

Post by Achim » Wed Nov 05, 2008 8:25 am

I've a problem with load and save, also.

Saving seems ok, but LoadChartFromFile deletes the series.

procedure TForm8.Button4Click(Sender: TObject);
begin
SaveChartToFile(DBChart3,'Chart.txt',True,true);
LineSeries1.Clear;
LineSeries2.clear;
end;

procedure TForm8.Button5Click(Sender: TObject);
begin
LoadChartFromFile(TCustomChart(DBChart3),'Chart.txt');
DBChart3.Refresh;
end;


After Load are the LineSeries are nil. What to do?

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

Post by Narcís » Wed Nov 05, 2008 9:46 am

Hi Achim,

This works fine for me here using TeeChart Pro v8.04 VCL. Which TeeChart version are you using?

You may need to register all series styles at runtime using TeeEditPro as described here.

If problem persists please send us a simple example project we can run "as-is" to reproduce the problem here.

You can post your files at news://www.steema.net/steema.public.attachments newsgroup or at our upload page.

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

Achim
Newbie
Newbie
Posts: 10
Joined: Tue Nov 27, 2007 12:00 am

Post by Achim » Wed Nov 05, 2008 11:11 am

This works fine for me here using TeeChart Pro v8.04 VCL. Which TeeChart version are you using?
8.02, but I've took a look at the 8.04bugfix-file. There is nothing about loadchartfromfile ...
You may need to register all series styles at runtime using TeeEditPro as described here.
I'he tried it, but it doesn't help.
If problem persists please send us a simple example project we can run "as-is" to reproduce the problem here.

You can post your files at our upload page.
There is a project and a compiled demo. (D2007)

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

Post by Narcís » Wed Nov 05, 2008 11:25 am

Hi Achim,

Thanks for the example project.

This is because after loading the chart Series1 variable hasn't been assigned but you can use loaded chart's series like this:

Code: Select all

procedure TForm1.Button2Click(Sender: TObject);
begin
  LoadChartFromFile(TCustomChart(DBChart1),'Chart.txt');
  if not(assigned(DBChart1[0])) then
     ShowMessage('Serie = nil');

  DBChart1[0].FillSampleValues();
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

Achim
Newbie
Newbie
Posts: 10
Joined: Tue Nov 27, 2007 12:00 am

Post by Achim » Wed Nov 05, 2008 2:13 pm


This is because after loading the chart Series1 variable hasn't been assigned
Thanks, I'll use DBChart1[0..n] instead of Series1..n

Is it a bug, which will fixed?

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

Post by Narcís » Wed Nov 05, 2008 2:21 pm

Hi Achim,

No, it's not a bug. Once you have exported a chart the variables you have in the unit you are using are no longer valid. On the other hand, you can then load charts you have saved in another application where any of those variables exists, just having a TChart/TDBChart object and loading the chart template would be enough.
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

srdjos
Newbie
Newbie
Posts: 3
Joined: Tue Aug 07, 2007 12:00 am

Post by srdjos » Wed Nov 12, 2008 12:59 pm

Hi

thanx for response

Problem has been solved before I've made a post here
simple, freeing and creating chart from beginning
and after that, calling LoadChartFromStream

Why you don't call that code, cleaning all series,
when LoadChartFromStream is issued ?

is this a bug or ?
narcis wrote:Hi Srdjan,

You can try clearing a chart before importing another one like this:
.
..
..
Hope this helps!

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

Post by Narcís » Wed Nov 12, 2008 1:52 pm

Hi srdjos,

I don't know the exact reason for this not being implemented but I've added it to the wish list to be considered for inclusion in next releases.
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

Post Reply