Page 1 of 3
Cannot load exported chart
Posted: Wed Jan 15, 2014 3:12 pm
by 15654539
I have exported one chart but know I cannot load it with this instruction "Import.Template.Load"
In the error message it says "{"Index was out of range. Must be non-negative and less than the size of the collection.\r\nParameter name: index"}" but how can I know better where is the problem?
this is the exported chart
http://193.145.251.126/pnp/files/hsYpWInRr/test2.ten
Thanks
Re: Cannot load exported chart
Posted: Wed Jan 15, 2014 4:13 pm
by Christopher
Hello,
wakeup wrote:
but how can I know better where is the problem?
The problem is due to a custom axis. A custom axis is deserialized but is not being correctly placed into the custom axes collection (Axis.Custom), hence the error. I'm not sure why this is occurring, as otherwise custom axes serialize without a problem, e.g.
Code: Select all
private void InitializeChart()
{
Line line = new Line(tChart1.Chart);
line.FillSampleValues();
Axis axis = new Axis(tChart1.Chart);
tChart1.Axes.Custom.Add(axis);
axis.Horizontal = false;
axis.RelativePosition = 30;
line.CustomVertAxis = axis;
}
private void button1_Click(object sender, EventArgs e)
{
MemoryStream stream = new MemoryStream();
tChart1.Export.Template.Save(stream);
tChart1.Clear();
MessageBox.Show("Clear");
stream.Position = 0;
tChart1.Import.Template.Load(stream);
}
Re: Cannot load exported chart
Posted: Wed Jan 15, 2014 4:32 pm
by 15654539
Thanks, yes I'm working with custom axis and I can serialize and deserialize without problems except in that case, is not possible to see what it have in special?
Thanks
Re: Cannot load exported chart
Posted: Wed Jan 15, 2014 5:03 pm
by Christopher
wakeup wrote:
Thanks, yes I'm working with custom axis and I can serialize and deserialize without problems except in that case, is not possible to see what it have in special?
It looks as if the series in your *.ten file have CustomVertAxis assigned, but that these axis objects are not present in the tChart1.Axes.Custom collection - are you quite sure you are adding them in? It would be interesting to see the code that produced that *.ten file.
Re: Cannot load exported chart
Posted: Wed Jan 15, 2014 5:12 pm
by 15654539
This is the code I have to create the custom axis for each serie
Code: Select all
for (int i = 0; i < chart.Series.Count; i++)
{
Steema.TeeChart.Axis customAxis = new Steema.TeeChart.Axis(chart.Chart);
customAxis.Title.Caption = txtTitle.Text;
customAxis.Visible = false;
customAxis.Automatic = !manualScale;
if (manualScale)
{
customAxis.Maximum = variables[i].maxScale.Value;
customAxis.Minimum = variables[i].minScale.Value;
}
chart.Axes.Custom.Add(customAxis);
chart.Series[i].CustomVertAxis = customAxis;
}
is there something wrong?
Thanks
Re: Cannot load exported chart
Posted: Wed Jan 15, 2014 5:25 pm
by Christopher
wakeup wrote:
is there something wrong?
Not that I can see, no. The following code works fine here:
Code: Select all
private void InitializeChart()
{
tChart1.Aspect.View3D = false;
for (int i = 0; i < 3; i++)
{
tChart1.Series.Add(typeof(Line)).FillSampleValues();
Steema.TeeChart.Axis customAxis = new Steema.TeeChart.Axis(tChart1.Chart);
customAxis.Title.Caption = "hello";
customAxis.RelativePosition = (i + 1) * 10;
customAxis.Visible = false;
tChart1.Axes.Custom.Add(customAxis);
tChart1.Series[i].CustomVertAxis = customAxis;
}
}
private void button1_Click(object sender, EventArgs e)
{
MemoryStream stream = new MemoryStream();
tChart1.Export.Template.Save(stream);
tChart1.Clear();
MessageBox.Show("Clear");
stream.Position = 0;
tChart1.Import.Template.Load(stream);
}
Re: Cannot load exported chart
Posted: Fri Jan 17, 2014 4:15 pm
by 15654539
I have aparrently the same error again but I think in this chart there arent custom axes.
Could you test it?
http://193.145.251.126/pnp/files/XfyapMBif/test3.ten
Is not possible to check in my own what is exactly wrong?
Thanks
Re: Cannot load exported chart
Posted: Mon Jan 20, 2014 9:05 am
by Christopher
Of course I will test it, but unfortunately test3.ten doesn't seem to be at this URL. Could you please check it for me?
Re: Cannot load exported chart
Posted: Tue Jan 21, 2014 9:38 am
by 15654539
Re: Cannot load exported chart
Posted: Tue Jan 21, 2014 5:23 pm
by Christopher
It is a custom axes which is again causing this failure. Could you please give me a code snippet which produces this *.ten file and with which I can recreate it here?
Re: Cannot load exported chart
Posted: Wed Jan 22, 2014 9:42 am
by 15654539
Here it is, althought I guess it is very simple...
Code: Select all
chart.Export.Template.IncludeData = includeData;
chart.Export.Template.Save(path);
Thanks
Re: Cannot load exported chart
Posted: Wed Jan 22, 2014 9:50 am
by Christopher
wakeup wrote:Here it is, althought I guess it is very simple...
Code: Select all
chart.Export.Template.IncludeData = includeData;
chart.Export.Template.Save(path);
Thanks
Sorry, but I am unable to reproduce the test3.ten using only the above two lines of code. Would you be so kind as to give me a fuller snippet with which I can recreate the test3.ten file in its entirety?
Re: Cannot load exported chart
Posted: Wed Jan 22, 2014 9:58 am
by 15654539
It's dificult, it's a big project which sets a lot of properties of teechart in different parts of the code.
In this post there is the code of creating the custom axis which are causing this failure. If you want the code of some other specific task I can send you but all the project is difficult...
Thanks
Re: Cannot load exported chart
Posted: Wed Jan 22, 2014 10:24 am
by Christopher
wakeup wrote:
In this post there is the code of creating the custom axis which are causing this failure.
Where is this code? As I mentioned, the following code works correctly here:
Code: Select all
private void InitializeChart()
{
tChart1.Aspect.View3D = false;
for (int i = 0; i < 3; i++)
{
tChart1.Series.Add(typeof(Line)).FillSampleValues();
Steema.TeeChart.Axis customAxis = new Steema.TeeChart.Axis(tChart1.Chart);
customAxis.Title.Caption = "hello";
customAxis.RelativePosition = (i + 1) * 10;
customAxis.Visible = false;
tChart1.Axes.Custom.Add(customAxis);
tChart1.Series[i].CustomVertAxis = customAxis;
}
}
private void button1_Click(object sender, EventArgs e)
{
MemoryStream stream = new MemoryStream();
tChart1.Export.Template.Save(stream);
tChart1.Clear();
MessageBox.Show("Clear");
stream.Position = 0;
tChart1.Import.Template.Load(stream);
}
Can you please modify this code so that it produces a 'stream' which gives the error you're experiencing when importing it?
Re: Cannot load exported chart
Posted: Wed Jan 22, 2014 10:44 am
by 15654539
Here is the code
http://www.teechart.net/support/viewtop ... 410#p64410
Yest that code works, and my code most of the times also works, but sometimes not and that is what I'm try to know why...