Page 1 of 1

Assigning series

Posted: Mon Jan 12, 2009 2:37 pm
by 14045174
Ok, this one took me a while to create a repro-case, partially because I needed to understand, what was going on. If you run the following code, the first time form will be shown just fine (do not resize it, just close), but the second time I am getting "Parameter is not valid" exception (in our production code we are getting "Index was outside the bounds of the array" exception again generated somewhere in your code). The funny thing is, that if you resize the form when it is shown the first time - then the second time it is shown just fine! In our production code we actually do not show the chart directly, instead we are setting programmaticaly its size, get its image and place it into our report, so resizing is not an option.

Code: Select all

        private void RunTest()
        {
            var chart = new TChart();
            var series = new Area(chart.Chart);
            series.FillSampleValues();

            ChangeSeriesTypeAndShowGraph(chart, new HorizBar(chart.Chart));
            ChangeSeriesTypeAndShowGraph(chart, new Pie(chart.Chart));
        }

        private static void ChangeSeriesTypeAndShowGraph(TChart chart, Series anotherSeries)
        {
            anotherSeries.Assign(chart[0]);
            chart.Series.Remove(chart[0]);

            using (var form = new Form())
            {
                form.Controls.Add(chart);
                chart.Dock = DockStyle.Fill;
                form.ShowDialog();
                form.Controls.Remove(chart);
            }
        }

Posted: Mon Jan 12, 2009 2:56 pm
by narcis
Hi UserLS,

Thanks for the code example. I could reproduce the issue here and added it (TF02013713) to the defect list.

In the meantime, a workaround is implementing RunTest method like this:

Code: Select all

		private void RunTest()
		{
			var chart = new TChart();
			var series = new Area(chart.Chart);
			series.FillSampleValues();			

			ChangeSeriesTypeAndShowGraph(chart, new HorizBar(chart.Chart));
			chart.Graphics3D.UseBuffer = false;
			ChangeSeriesTypeAndShowGraph(chart, new Pie(chart.Chart));
			chart.Graphics3D.UseBuffer = true;
		}

Posted: Mon Jan 12, 2009 3:43 pm
by 14045174
I did try to put your fix into my program, but it did not work. So, I hope you guys will fix the bug soon enough for us (we still have some time to go before our prime time).

Posted: Mon Jan 12, 2009 3:45 pm
by narcis
Hi UserLS,

What about setting UseBuffer to false without setting it back to true? If this doesn't help, where does the application crash?

Thanks in advance.

Posted: Mon Jan 12, 2009 4:18 pm
by 14045174
I did try it. The app is crashing in 2 different places, depending what code path we take:
  • If I just want to get the image like following, it fails:

    Code: Select all

          FImage.Image = teeGraph.Chart.Metafile(new MemoryStream(), teeGraph.Chart, teeGraph.Width, teeGraph.Height, EmfType.EmfPlusOnly);
    
  • If I want to make some adjustments first and so try to show graph, it will fail on another call, which is a bit surprising, since the same line of code is executed just fine just before the line in the previous example:

    Code: Select all

          teeGraph.Refresh();
    

Posted: Tue Jan 13, 2009 8:52 am
by narcis
Hi UserLS,

Can you please send us a simple example project or a code snippet we can run "as-is" to try to find a workaround for it?

You can either post your files at news://www.steema.net/steema.public.attachments newsgroup or at our upload page.

Thanks in advance.

Posted: Tue Jan 13, 2009 2:55 pm
by 14045174
It took me a lot of time to even understand all the pieces of the puzzle to produce the first example... I do not know, what else is involved in the picture in our app. And it is rather complicated. I will try to figure out how to produce the problem outside the app, but it can take time... Hopefully, if you fix the bug with assign, it will take care of the problem.

Re: Assigning series

Posted: Thu Nov 12, 2009 4:20 pm
by narcis
Hello UserLS,

We have been investigating TF02013713 here and found that's not a bug but a technique. Implementing ChangeSeriesTypeAndShowGraph as in the code below solves the problem. Can you please check if this solves the issue at your end?

Code: Select all

		public Form1()
		{
			InitializeComponent();
			RunTest();
		}

		private void RunTest()
		{
			var chart = new TChart();
			var series = new Steema.TeeChart.Styles.Area(chart.Chart);
			series.FillSampleValues();


			ChangeSeriesTypeAndShowGraph(chart, new Steema.TeeChart.Styles.HorizBar(chart.Chart));
			ChangeSeriesTypeAndShowGraph(chart, new Steema.TeeChart.Styles.Pie(chart.Chart));
		}

		private static void ChangeSeriesTypeAndShowGraph(TChart chart, Steema.TeeChart.Styles.Series anotherSeries)
		{
			anotherSeries.Assign(chart[0]);
			chart.Series.Remove(chart[0]);

			using (var form = new Form())
			{
				form.Controls.Add(chart);
				chart.Dock = DockStyle.Fill;
				form.ShowDialog();
				form.Controls.Remove(chart);
				chart.Chart.Graphics3D.BackBuffer.Dispose(); //this backbuffer is associated with the form that's about to die
				chart.Chart.Graphics3D.BackBuffer = null;
			}
		}
Thanks in advance.

BTW: In TeeChart for .NET 2009 you could also do this:

Code: Select all

      var chart = new TChart();
      chart.Graphics3D.BufferStyle = BufferStyle.DoubleBuffer;

Re: Assigning series

Posted: Thu Nov 12, 2009 4:41 pm
by 14045174
Thanks for your reply, but this solution is not working anyway... What I've found during this time - your assign series does not work correctly, when the series is created programmatically and has not been pained. In my case, I need to be able to "copy" series from one chart to another (all in memory) and it does not play well. I ended up writing my own assign method to do it correctly, which gets really annoying (we already were forced to create our own chart editor as well).