Chart Streaming
Chart Streaming
Are all published values of a chart streamed with SaveChartToStream? I switched on Left and Bottom axis grid lines at runtime, saved the chart to stream, re-loaded the stream into another chart and gridlines where gone. How do i verify the contents of the outgoing stream - is there a way to get a text (dfm-style) representation of the chart, or is it a proprietry format?
Hi Gilbert,
I've tried with the folloiwng code and works fine here (using the latest TeeChart Pro v7) , all grid pen style is saved, could you please test if it works for you ?
Yes, if you want to save all the settings you'll have to use SaveChartToFile or SaveChartToStream method to save chart (with or without data) and then use LoadChartFromFile or LoadChartFromStream method to load chart "settings".Are all published values of a chart streamed with SaveChartToStream? I switched on Left and Bottom axis grid lines at runtime, saved the chart to stream, re-loaded the stream into another chart and gridlines where gone.
I've tried with the folloiwng code and works fine here (using the latest TeeChart Pro v7) , all grid pen style is saved, could you please test if it works for you ?
Code: Select all
Uses TeeStore, EditChar;
{$R *.dfm}
procedure TForm1.FormCreate(Sender: TObject);
begin
Series1.FillSampleValues(10);
Chart1.Axes.Left.Grid.Style := psSolid;
end;
procedure TForm1.BitBtn1Click(Sender: TObject);
Begin
memStream := TMemoryStream.Create;
SaveChartToStream(Chart1,memStream,true,true);
Chart1.RemoveAllSeries;
end;
procedure TForm1.BitBtn2Click(Sender: TObject);
begin
memStream.Position := 0;
Chart2.AutoRepaint := False;
LoadChartFromStream(tCustomChart(Chart1),memStream);
end;
You can save the stream or file as text, setting to true the last parameter of the methods.How do i verify the contents of the outgoing stream - is there a way to get a text (dfm-style) representation of the chart, or is it a proprietry format?
Pep Jorge
http://support.steema.com
http://support.steema.com
That's all cool, stream is saving properly, but - default values are not saved to stream. So, it seems, that when the chart is streamed in, values not in the stream are not set, hence my problem:
Gridlines is True by default.
I am streaming onto a chart where Gridlines is False and, since the property is not in the stream, it is not changed.
Since i cannot reset all default properties in the chart before streaming, here is a workaround:
procedure TFrameChart.SetupLayout(Layout: string);
var
ssTemp : TStringStream;
tcTemp : TCustomChart;
begin
if (Trim(Layout) <> EMPTY_STRING) then
begin
ssTemp := TStringStream.Create(Layout);
try
tcTemp := TDBChart.Create(Self);
try
LoadChartFromStream(tcTemp, ssTemp);
tcChart.Assign(tcTemp);
finally
tcTemp.Free;
end;
AssignEvents;
finally
ssTemp.Free;
end;
end;
end;
The AssignEvents procedure also seems to be neccessary - i have to set all fixed events to nil before streaming out as, when the chart is streamed in, having events causes some kind of Invalid Property error. Is there something I am doing wrong?
Gridlines is True by default.
I am streaming onto a chart where Gridlines is False and, since the property is not in the stream, it is not changed.
Since i cannot reset all default properties in the chart before streaming, here is a workaround:
procedure TFrameChart.SetupLayout(Layout: string);
var
ssTemp : TStringStream;
tcTemp : TCustomChart;
begin
if (Trim(Layout) <> EMPTY_STRING) then
begin
ssTemp := TStringStream.Create(Layout);
try
tcTemp := TDBChart.Create(Self);
try
LoadChartFromStream(tcTemp, ssTemp);
tcChart.Assign(tcTemp);
finally
tcTemp.Free;
end;
AssignEvents;
finally
ssTemp.Free;
end;
end;
end;
The AssignEvents procedure also seems to be neccessary - i have to set all fixed events to nil before streaming out as, when the chart is streamed in, having events causes some kind of Invalid Property error. Is there something I am doing wrong?
Hi Gilbert,
No, this is by default, the events are not saved, you've done the correct steps, set all the events to nil before export the Chart and then reasign all again when the Chart is imported.The AssignEvents procedure also seems to be neccessary - i have to set all fixed events to nil before streaming out as, when the chart is streamed in, having events causes some kind of Invalid Property error. Is there something I am doing wrong?
Pep Jorge
http://support.steema.com
http://support.steema.com