Cannot load exported chart

TeeChart for Microsoft Visual Studio .NET, Xamarin Studio (Android, iOS & Forms) & Monodevelop.
acastro
Advanced
Posts: 204
Joined: Tue Oct 27, 2009 12:00 am

Cannot load exported chart

Post by acastro » Wed Jan 15, 2014 3:12 pm

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

Christopher
Guru
Posts: 1603
Joined: Fri Nov 15, 2002 12:00 am

Re: Cannot load exported chart

Post by Christopher » Wed Jan 15, 2014 4:13 pm

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);
    }
Best Regards,
Christopher Ireland / Development & Support
Steema Software
Avinguda Montilivi 33, 17003 Girona, Catalonia
Tel: 34 972 218 797
http://www.steema.com
Instructions - How to post in this forum

acastro
Advanced
Posts: 204
Joined: Tue Oct 27, 2009 12:00 am

Re: Cannot load exported chart

Post by acastro » Wed Jan 15, 2014 4:32 pm

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

Christopher
Guru
Posts: 1603
Joined: Fri Nov 15, 2002 12:00 am

Re: Cannot load exported chart

Post by Christopher » Wed Jan 15, 2014 5:03 pm

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.
Best Regards,
Christopher Ireland / Development & Support
Steema Software
Avinguda Montilivi 33, 17003 Girona, Catalonia
Tel: 34 972 218 797
http://www.steema.com
Instructions - How to post in this forum

acastro
Advanced
Posts: 204
Joined: Tue Oct 27, 2009 12:00 am

Re: Cannot load exported chart

Post by acastro » Wed Jan 15, 2014 5:12 pm

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

Christopher
Guru
Posts: 1603
Joined: Fri Nov 15, 2002 12:00 am

Re: Cannot load exported chart

Post by Christopher » Wed Jan 15, 2014 5:25 pm

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);
    }
Best Regards,
Christopher Ireland / Development & Support
Steema Software
Avinguda Montilivi 33, 17003 Girona, Catalonia
Tel: 34 972 218 797
http://www.steema.com
Instructions - How to post in this forum

acastro
Advanced
Posts: 204
Joined: Tue Oct 27, 2009 12:00 am

Re: Cannot load exported chart

Post by acastro » Fri Jan 17, 2014 4:15 pm

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

Christopher
Guru
Posts: 1603
Joined: Fri Nov 15, 2002 12:00 am

Re: Cannot load exported chart

Post by Christopher » Mon Jan 20, 2014 9:05 am

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?
Best Regards,
Christopher Ireland / Development & Support
Steema Software
Avinguda Montilivi 33, 17003 Girona, Catalonia
Tel: 34 972 218 797
http://www.steema.com
Instructions - How to post in this forum

acastro
Advanced
Posts: 204
Joined: Tue Oct 27, 2009 12:00 am

Re: Cannot load exported chart

Post by acastro » Tue Jan 21, 2014 9:38 am


Christopher
Guru
Posts: 1603
Joined: Fri Nov 15, 2002 12:00 am

Re: Cannot load exported chart

Post by Christopher » Tue Jan 21, 2014 5:23 pm

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?
Best Regards,
Christopher Ireland / Development & Support
Steema Software
Avinguda Montilivi 33, 17003 Girona, Catalonia
Tel: 34 972 218 797
http://www.steema.com
Instructions - How to post in this forum

acastro
Advanced
Posts: 204
Joined: Tue Oct 27, 2009 12:00 am

Re: Cannot load exported chart

Post by acastro » Wed Jan 22, 2014 9:42 am

Here it is, althought I guess it is very simple...

Code: Select all

          chart.Export.Template.IncludeData = includeData;
            chart.Export.Template.Save(path);

Thanks

Christopher
Guru
Posts: 1603
Joined: Fri Nov 15, 2002 12:00 am

Re: Cannot load exported chart

Post by Christopher » Wed Jan 22, 2014 9:50 am

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?
Best Regards,
Christopher Ireland / Development & Support
Steema Software
Avinguda Montilivi 33, 17003 Girona, Catalonia
Tel: 34 972 218 797
http://www.steema.com
Instructions - How to post in this forum

acastro
Advanced
Posts: 204
Joined: Tue Oct 27, 2009 12:00 am

Re: Cannot load exported chart

Post by acastro » Wed Jan 22, 2014 9:58 am

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

Christopher
Guru
Posts: 1603
Joined: Fri Nov 15, 2002 12:00 am

Re: Cannot load exported chart

Post by Christopher » Wed Jan 22, 2014 10:24 am

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?
Best Regards,
Christopher Ireland / Development & Support
Steema Software
Avinguda Montilivi 33, 17003 Girona, Catalonia
Tel: 34 972 218 797
http://www.steema.com
Instructions - How to post in this forum

acastro
Advanced
Posts: 204
Joined: Tue Oct 27, 2009 12:00 am

Re: Cannot load exported chart

Post by acastro » Wed Jan 22, 2014 10:44 am

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...

Post Reply