Cannot load exported chart

TeeChart for Microsoft Visual Studio .NET, Xamarin Studio (Android, iOS & Forms) & Monodevelop.
Christopher
Guru
Posts: 1603
Joined: Fri Nov 15, 2002 12:00 am

Re: Cannot load exported chart

Post by Christopher » Wed Jan 22, 2014 11:05 am

wakeup wrote: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...
Just by looking at the *.ten file, which I have done, I'm afraid I am unable to extrapolate the code that created it. Without the code that created it, I cannot arrive at any definitive solution to the problem. I'm sure you understand the position I am in.

All I can suggest is that you try to work on a small code snippet which can create a *.ten file that exhibits this erroneous behaviour. I'm sorry I can't immediately resolve this problem for you.
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 11:31 am

It is difficult, because I cannot reproduce it when I want...

When it fails it gives this error
{"Index was out of range. Must be non-negative and less than the size of the collection.\r\nParameter name: index"}
Can you see what index is exactly out of range? It could be a clue...

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 11:39 am

wakeup wrote: Can you see what index is exactly out of range? It could be a clue...
As I said here:
A custom axis is deserialized but is not being correctly placed into the custom axes collection (Axis.Custom), hence the error.
Are you try to serialize a chart with a custom axis which is NOT added into the Axis.Custom collection? That's what might be happening. I see that the following code gives a similar error:

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); //with this line commented, an error
      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 22, 2014 12:40 pm

A custom axis is deserialized but is not being correctly placed into the custom axes collection (Axis.Custom), hence the error.
So only one customaxis is in the .ten file?
Are you try to serialize a chart with a custom axis which is NOT added into the Axis.Custom collection? That's what might be happening. I see that the following code gives a similar error:
I don't think it, al least with the code of generating it it is impossible.
But when I delete the custom axis I do this. Is it right?

Code: Select all

chart.Axes.Custom.Clear();
for (int i = 0; i < chart.Series.Count; i++)
{
                    chart.Series[i].CustomVertAxis = chart.Axes.Left;
}

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

Re: Cannot load exported chart

Post by Christopher » Wed Jan 22, 2014 12:53 pm

wakeup wrote: So only one customaxis is in the .ten file?
I don't know, as the code throws an exception on the first custom axes, I don't know how many more there are. I do know that all the series have an object assigned to CustomVertAxis, but I don't know if it is a default axis or a custom axis.
wakeup wrote: I don't think it, al least with the code of generating it it is impossible.
Okay.
wakeup wrote: But when I delete the custom axis I do this. Is it right?
No, it is not. You should do this:

Code: Select all

    private void InitializeChart()
    {
      tChart1.Aspect.View3D = false;
      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)
    {
      tChart1.Axes.Custom.Clear();
      tChart1[0].CustomVertAxis = null;
      tChart1[0].VertAxis = VerticalAxis.Left;
    }
Maybe the series with an object assigned to CustomVertAxis I mentioned above are due to your erroneous assignment of the CustomVertAxis to a default axis.
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 2:57 pm

Ok I changed it, I will see it the problem doesn't reproduce again.
Thanks a lot

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

Re: Cannot load exported chart

Post by Christopher » Wed Jan 22, 2014 4:16 pm

wakeup wrote:Ok I changed it, I will see it the problem doesn't reproduce again.
Thanks a lot
I'm very glad to hear it :)

You're welcome!
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 Mar 11, 2014 12:26 pm

The error didn't appear again in a lot of time. But last days I have been adding the pagescroller and now the error has come back again.


The error message is the same but perhaps it is related to other issue. Could you see it?



http://193.145.251.126/pnp/files/gqjsivcOH/error.ten

Thanks

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

Re: Cannot load exported chart

Post by Christopher » Tue Mar 11, 2014 4:36 pm

wakeup wrote:The error message is the same but perhaps it is related to other issue. Could you see it?
What I can see is that you have two Custom Axes in the CustomAxes collection (Axes.Custom) but have a third Custom Axis which is not in it. It is this third custom axis which has not been added to the CustomAxes collection which is causing the problem.
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 Mar 12, 2014 9:58 am

I check it just before save it in "chart.Axes.Custom.Count" and it says 2. Where can find that third axis?

Thanks

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

Re: Cannot load exported chart

Post by Christopher » Wed Mar 12, 2014 10:11 am

wakeup wrote:I check it just before save it in "chart.Axes.Custom.Count" and it says 2. Where can find that third axis?
I don't know. I'm afraid I do not have access to the code that produced the *.ten file, and I cannot see from debugging the *.ten file from where that third axis comes from.

Can you please give me the code that produces the *.ten file? That way I will be able to help you further.
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 Mar 12, 2014 10:28 am

I have found if I comment this code it doesn't happens:

Code: Select all

 
if (pagescrolleractivated)
            {

                Steema.TeeChart.Axis axis = null;
                if (graph.scale.mode == Entities.Scale.MULTIPLE)
                {
                    if (graph.scale.current >= 0)
                    {

                        axis = chart.Series[graph.scale.current].CustomVertAxis;
                        chart.Series[graph.scale.current].CustomVertAxis = null;
                        chart.Series[graph.scale.current].VertAxis = Steema.TeeChart.Styles.VerticalAxis.Left;
  
                    }
                }

                for (int i = 0; i < chart.Tools.Count; i++)
                {
                    if (chart.Tools[i].GetType().Name.Equals("ScrollPager"))
                    {
                        //((ScrollPager)chart.Tools[i]).Series = null;
                        ((ScrollPager)chart.Tools[i]).SubChartTChart.Clear();

                        ((ScrollPager)chart.Tools[i]).SubChartTChart.Legend.Visible = false;
                        for (int j = 0; j < chart.Series.Count; j++)
                        {
                            if (chart.Series[j].Count > 0)
                                ((ScrollPager)chart.Tools[i]).Series = chart.Series[j];
                        }
                    }
                }



                if (graph.scale.mode == Entities.Scale.MULTIPLE)
                {
                    if (graph.scale.current >= 0)
                    {

                        chart.Series[graph.scale.current].CustomVertAxis = axis;
                    }
                }
This code is for update the series of the pagescroller when the user has changed the values. I have to quit the custom axis, and put it again after add de series as you said in this post http://www.teechart.net/support/viewtop ... 108#p65108

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

Re: Cannot load exported chart

Post by Christopher » Wed Mar 12, 2014 11:54 am

wakeup wrote:I have found if I comment this code it doesn't happens:
I'm sorry, but that code snippet is insufficient for me to diagnose what the problem could be.

Would you be so kind as to give me a more complete example of how the erroneous *.ten file is created?
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 Mar 12, 2014 3:21 pm

With more code I think it would be more difficult...

I have find if I run this code to refresh the series it save it in bad way, if I don't run this code it saves and open without problems...

Code: Select all

                
for (int i = 0; i < chart.Tools.Count; i++)
                {
                    if (chart.Tools[i].GetType().Name.Equals("ScrollPager"))
                    {

                        ((ScrollPager)chart.Tools[i]).SubChartTChart.Clear();

                        ((ScrollPager)chart.Tools[i]).SubChartTChart.Legend.Visible = false;
                        for (int j = 0; j < chart.Series.Count; j++)
                        {
                            if (chart.Series[j].Count > 0)
                                ((ScrollPager)chart.Tools[i]).Series = chart.Series[j];
                        }
                    }
                }

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

Re: Cannot load exported chart

Post by Christopher » Wed Mar 12, 2014 3:27 pm

wakeup wrote:I have find if I run this code to refresh the series it save it in bad way, if I don't run this code it saves and open without problems...
Okay. How can I be of help here? I'm afraid I cannot tell you why one of your code snippets works and one of them doesn't just by looking at it. Without being able to run those code snippets in a broader code context I cannot diagnose exactly what the problem is, I'm sorry.
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

Post Reply