Page 1 of 1
LoadChartFromStream / SaveChartToStream
Posted: Tue Nov 04, 2008 12:55 pm
by 10546323
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
Posted: Tue Nov 04, 2008 3:23 pm
by narcis
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!
Posted: Wed Nov 05, 2008 8:25 am
by 10547507
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?
Posted: Wed Nov 05, 2008 9:46 am
by narcis
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.
Posted: Wed Nov 05, 2008 11:11 am
by 10547507
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)
Posted: Wed Nov 05, 2008 11:25 am
by narcis
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;
Posted: Wed Nov 05, 2008 2:13 pm
by 10547507
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?
Posted: Wed Nov 05, 2008 2:21 pm
by narcis
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.
Posted: Wed Nov 12, 2008 12:59 pm
by 10546323
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!
Posted: Wed Nov 12, 2008 1:52 pm
by narcis
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.