Problems to open a Gauge (csharp .net)
Posted: Tue Nov 06, 2018 8:35 am
Hello,
My name is Tony. I hope somebody can help me. Many thanks in advance!
I have a Project (Visual Studio 2012) with TChart v.2018. When I try to serialize and deserialize a Gauge to save it and open I receive an error.
This is the way I'm doing it:
- To save:
public void nativeSerialize(Steema.TeeChart.TChart chart, bool includeData)
{
// Guardar archivo a carpeta temporal
string path = System.IO.Path.GetTempPath() + @"\temp" + System.DateTime.Now.Millisecond.ToString() + ".ten";
chart.Export.Template.IncludeData = includeData;
chart.Export.Template.Save(path);
byte[] buff = null;
FileStream fs = new FileStream(path, FileMode.Open, FileAccess.Read);
BinaryReader stream = new BinaryReader(fs);
int LengthOfBuffer = (int)fs.Length;
// the buffer for contents of the file
buff = new byte[LengthOfBuffer];
// read the file into the buffer
for (int i = 0; i < LengthOfBuffer; i++)
buff = stream.ReadByte();
// close the file
stream.Close();
fs.Close();
this.native = Convert.ToBase64String(buff);
File.Delete(path);
}
- To open:
public void nativeDeSerialize(Steema.TeeChart.TChart chart)
{
byte[] buff2 = Convert.FromBase64String(this.native);
string path = System.IO.Path.GetTempPath() + @"\temp" + System.DateTime.Now.Millisecond.ToString() + ".ten";
FileStream fsOut = new FileStream(path, FileMode.Create, FileAccess.Write);
BinaryWriter streamOut = new BinaryWriter(fsOut);
streamOut.Write(buff2);
streamOut.Close();
fsOut.Close();
chart.Import.Template.Load(path); << here I get the error (*)
File.Delete(path);
}
(*) Error: {"Index was out of range. Must be non-negative and less than the size of the collection.\r\nParameter name: index"}
This way is the same I do with another types of Graphs (histogram, for example) and I have no problems. And also, I don't receive any error if I use an older versión of TChart (2014)
If you need any more details or information, please tell me.
Thanks,
Tony
My name is Tony. I hope somebody can help me. Many thanks in advance!
I have a Project (Visual Studio 2012) with TChart v.2018. When I try to serialize and deserialize a Gauge to save it and open I receive an error.
This is the way I'm doing it:
- To save:
public void nativeSerialize(Steema.TeeChart.TChart chart, bool includeData)
{
// Guardar archivo a carpeta temporal
string path = System.IO.Path.GetTempPath() + @"\temp" + System.DateTime.Now.Millisecond.ToString() + ".ten";
chart.Export.Template.IncludeData = includeData;
chart.Export.Template.Save(path);
byte[] buff = null;
FileStream fs = new FileStream(path, FileMode.Open, FileAccess.Read);
BinaryReader stream = new BinaryReader(fs);
int LengthOfBuffer = (int)fs.Length;
// the buffer for contents of the file
buff = new byte[LengthOfBuffer];
// read the file into the buffer
for (int i = 0; i < LengthOfBuffer; i++)
buff = stream.ReadByte();
// close the file
stream.Close();
fs.Close();
this.native = Convert.ToBase64String(buff);
File.Delete(path);
}
- To open:
public void nativeDeSerialize(Steema.TeeChart.TChart chart)
{
byte[] buff2 = Convert.FromBase64String(this.native);
string path = System.IO.Path.GetTempPath() + @"\temp" + System.DateTime.Now.Millisecond.ToString() + ".ten";
FileStream fsOut = new FileStream(path, FileMode.Create, FileAccess.Write);
BinaryWriter streamOut = new BinaryWriter(fsOut);
streamOut.Write(buff2);
streamOut.Close();
fsOut.Close();
chart.Import.Template.Load(path); << here I get the error (*)
File.Delete(path);
}
(*) Error: {"Index was out of range. Must be non-negative and less than the size of the collection.\r\nParameter name: index"}
This way is the same I do with another types of Graphs (histogram, for example) and I have no problems. And also, I don't receive any error if I use an older versión of TChart (2014)
If you need any more details or information, please tell me.
Thanks,
Tony