Page 1 of 1

How to save/load a chart template from a database ?

Posted: Thu Dec 07, 2006 5:36 pm
by 9640747
Hello,

I would like to know what is the best practice for saving/loading a chart template into a Database field (Sql Server in the case in point). What type of field use in the Db (varbinary ?).
I've done some tests but if the save job work good the load one always throw a exception because of a Truncate stream when using TeeChart.Import.Load().

The Load code :

Code: Select all

System.IO.MemoryStream _stream = new System.IO.MemoryStream(GraphLayout);
this.tChart1.Import.Template.Load(_stream);
where GraphLayout is a Byte[] array readed from the db.

The Save code:

Code: Select all

System.IO.MemoryStream _stream = new System.IO.MemoryStream();
this.tChart1.Export.Template.Save(_stream);
GraphLayout = _stream.GetBuffer();

Posted: Mon Dec 11, 2006 11:48 am
by narcis
Hi jfb,

Have you tried setting stream's position to zero before loading it into the chart? For example:

Code: Select all

System.IO.MemoryStream _stream = new System.IO.MemoryStream(GraphLayout);
_stream.Position = 0;
this.tChart1.Import.Template.Load(_stream); 

Posted: Tue Dec 12, 2006 9:51 am
by 9640747
Thanks for your response,

I've done the stream position setting to 0 but the problem still occur.
I think there is a problem with the Export.Template.Save() method, I've notice that some times I catch the Exception below when trying to save the chart (ten file or stream) :

(translation from French, may be some some differences in real english message).
The 'TextContrast' property accessor on object 'System.Drawing.Graphics' has thrown a exception : 'invalid parameter'

à System.ComponentModel.ReflectPropertyDescriptor.GetValue(Object component)
à Steema.TeeChart.Export.TemplateExport.SerializeProperty(String Title, Object value, PropertyDescriptor i, SerializationInfo info)
à Steema.TeeChart.Export.TemplateExport.SerializeObject(String Prefix, Object value, SerializationInfo info)
à Steema.TeeChart.Export.TemplateExport.SerializeProperty(String Title, Object value, PropertyDescriptor i, SerializationInfo info)
à Steema.TeeChart.Export.TemplateExport.SerializeObject(String Prefix, Object value, SerializationInfo info)
à Steema.TeeChart.Export.TemplateExport.SerializeProperty(String Title, Object value, PropertyDescriptor i, SerializationInfo info)
à Steema.TeeChart.Export.TemplateExport.SerializeObject(String Prefix, Object value, SerializationInfo info)
à Steema.TeeChart.Export.TemplateExport.Serialize(SerializationInfo info, StreamingContext context)
à Steema.TeeChart.Chart.GetObjectData(SerializationInfo info, StreamingContext context)
à System.Runtime.Serialization.Formatters.Binary.WriteObjectInfo.InitSerialize(Object obj, ISurrogateSelector surrogateSelector, StreamingContext context, SerObjectInfoInit serObjectInfoInit, IFormatterConverter converter, ObjectWriter objectWriter)
à System.Runtime.Serialization.Formatters.Binary.WriteObjectInfo.Serialize(Object obj, ISurrogateSelector surrogateSelector, StreamingContext context, SerObjectInfoInit serObjectInfoInit, IFormatterConverter converter, ObjectWriter objectWriter)
à System.Runtime.Serialization.Formatters.Binary.ObjectWriter.Serialize(Object graph, Header[] inHeaders, __BinaryWriter serWriter, Boolean fCheck)
à System.Runtime.Serialization.Formatters.Binary.BinaryFormatter.Serialize(Stream serializationStream, Object graph, Header[] headers, Boolean fCheck)
à System.Runtime.Serialization.Formatters.Binary.BinaryFormatter.Serialize(Stream serializationStream, Object graph)
à Steema.TeeChart.Export.TemplateExport.Serialize(Stream stream)
à Steema.TeeChart.Export.TemplateExport.Save(Stream stream)
à Steema.TeeChart.Export.TemplateExport.Save(String FileName)



May be it could be related to this post from Adrian
http://www.teechart.net/support/viewtop ... plate+save

Yann.

Posted: Tue Dec 12, 2006 10:05 am
by narcis
Hi Yann,

Yes, it seems to be the same issue as you pointed. It is already a high priority item on our defect list to be investigated fixed for the next releases.