Converting Series type Line to Area

TeeChart for Microsoft Visual Studio .NET, Xamarin Studio (Android, iOS & Forms) & Monodevelop.
Post Reply
Quant
Advanced
Posts: 142
Joined: Tue Dec 30, 2014 12:00 am

Converting Series type Line to Area

Post by Quant » Fri Jan 30, 2015 11:24 am

While converting Series type Line to Area I am getting
"System.NullReferenceException - Object reference not set to an instance of an object."

I used following code.

Code: Select all

                Steema.TeeChart.Styles.Series tSeries = tChartMain[0];
                Steema.TeeChart.Styles.Series.ChangeType(ref tSeries, typeof(Steema.TeeChart.Styles.Area));
                Steema.TeeChart.Styles.Area tArea = (Steema.TeeChart.Styles.Area)tChartMain.Series[0];
Kindly Help in resolving this issue.

Narcís
Site Admin
Site Admin
Posts: 14730
Joined: Mon Jun 09, 2003 4:00 am
Location: Banyoles, Catalonia
Contact:

Re: Converting Series type Line to Area

Post by Narcís » Fri Jan 30, 2015 12:32 pm

Hello Quant,

This is a bug which I have added to our bug tracking system (ID1109). I also fixed it for the next maintenance release. In the meantime you can do something like this:

Code: Select all

      tChart1.Series.Add(new Steema.TeeChart.Styles.Line()).FillSampleValues();

      Steema.TeeChart.Styles.Series tSeries = tChart1[0];
      //Steema.TeeChart.Styles.Series.ChangeType(ref tSeries, typeof(Steema.TeeChart.Styles.Area));
      Steema.TeeChart.Styles.Area tArea = new Steema.TeeChart.Styles.Area(tChart1.Chart);
      tArea.DataSource = tSeries;
      tArea.Color = tSeries.Color;
      tArea.LinePen.Color = (tChart1[0] as Steema.TeeChart.Styles.Line).LinePen.Color;
      tArea.AreaLines.Color = tArea.LinePen.Color;

      tChart1.Series.Remove(tSeries);
Best Regards,
Narcís Calvet / Development & Support
Steema Software
Avinguda Montilivi 33, 17003 Girona, Catalonia
Tel: 34 972 218 797
http://www.steema.com
Image Image Image Image Image Image
Instructions - How to post in this forum

Quant
Advanced
Posts: 142
Joined: Tue Dec 30, 2014 12:00 am

Re: Converting Series type Line to Area

Post by Quant » Mon Feb 02, 2015 4:35 am

Thank you for your reply and workaround.
The Bugzilla link provided by you is showing the status RESOLVED FIXED.
Kindly send me the new solution.

Narcís
Site Admin
Site Admin
Posts: 14730
Joined: Mon Jun 09, 2003 4:00 am
Location: Banyoles, Catalonia
Contact:

Re: Converting Series type Line to Area

Post by Narcís » Mon Feb 02, 2015 8:21 am

Hello Quant,

I see you are a source code customer. In that case you should add the code snippet below at the private void Steema.TeeChart.Styles.Custom.DrawArea(Color BrushColor, int x, int y, int valueIndex) method in Custom.cs

Code: Select all

      if (bAreaBrush == null)
      {
        bAreaBrush = new ChartBrush();
      }
This should be added below those lines:

Code: Select all

      Graphics3D g = chart.graphics3D;
      bool oldBrushVisible = false;
Something like this:

Code: Select all

      Graphics3D g = chart.graphics3D;
      bool oldBrushVisible = false;

      if (bAreaBrush == null)
      {
        bAreaBrush = new ChartBrush();
      }

      if (ColorEach)
      {
        //code continues here
Best Regards,
Narcís Calvet / Development & Support
Steema Software
Avinguda Montilivi 33, 17003 Girona, Catalonia
Tel: 34 972 218 797
http://www.steema.com
Image Image Image Image Image Image
Instructions - How to post in this forum

Quant
Advanced
Posts: 142
Joined: Tue Dec 30, 2014 12:00 am

Re: Converting Series type Line to Area

Post by Quant » Mon Feb 02, 2015 12:28 pm

Now getting same error Object reference not set to an instance of an object.
on line no. 3548 that is

Code: Select all

 oldPenColor = pAreaLines.Color;
which is in DrawPoint() Method of Custom.cs

Code: Select all

       if (drawArea)
        {
          Color tmp = GetAreaBrushColor(tmpColor);
          oldPenColor = pAreaLines.Color;

          if (pAreaLines.Visible)
          {
            if (ColorEach)
            {
              pAreaLines.Color = Utils.DarkenColor(tmp, 60);
            }
          }
          else
          {
            pAreaLines.Color = tmp;
          }

          g.Pen = pAreaLines;

          DrawArea(tmp, x, y, valueIndex);

          pAreaLines.Color = oldPenColor;
        }

Narcís
Site Admin
Site Admin
Posts: 14730
Joined: Mon Jun 09, 2003 4:00 am
Location: Banyoles, Catalonia
Contact:

Re: Converting Series type Line to Area

Post by Narcís » Mon Feb 02, 2015 12:37 pm

Hello Quant,

Does it occur running the same code I added at bugzilla?

Code: Select all

      tChart1.Series.Add(new Steema.TeeChart.Styles.Line()).FillSampleValues();

      Steema.TeeChart.Styles.Series tSeries = tChart1[0];
      Steema.TeeChart.Styles.Series.ChangeType(ref tSeries, typeof(Steema.TeeChart.Styles.Area));
That being the case you might need more changes that have been implemented at our internal sources since the last maintenance release and you should wait for the next one.

Otherwise, please send us a simple code snippet we can run "as-is" to reproduce the problem here.

Thanks in advance.
Best Regards,
Narcís Calvet / Development & Support
Steema Software
Avinguda Montilivi 33, 17003 Girona, Catalonia
Tel: 34 972 218 797
http://www.steema.com
Image Image Image Image Image Image
Instructions - How to post in this forum

Narcís
Site Admin
Site Admin
Posts: 14730
Joined: Mon Jun 09, 2003 4:00 am
Location: Banyoles, Catalonia
Contact:

Re: Converting Series type Line to Area

Post by Narcís » Mon Feb 02, 2015 1:10 pm

Hello Quant,
Narcís wrote: That being the case you might need more changes that have been implemented at our internal sources since the last maintenance release
You could also check if pAreaLines is being initialized at AreaLines property in Area.cs, for example:

Code: Select all

public ChartPen AreaLines 
{
	get
	{        
		if (pAreaLines == null) pAreaLines = new ChartPen(chart, Color.Black);

		return pAreaLines; 
	}
}
Best Regards,
Narcís Calvet / Development & Support
Steema Software
Avinguda Montilivi 33, 17003 Girona, Catalonia
Tel: 34 972 218 797
http://www.steema.com
Image Image Image Image Image Image
Instructions - How to post in this forum

Post Reply