Page 1 of 1

Area series with color crashes when legend is invisible

Posted: Thu Jun 05, 2014 9:07 am
by 15667374
I have TeeChart 4.1.2013.11082 for .Net WinForms.
When I want to use Area series with my own color on chart with hidden legend then it crashes with NullReferenceException.

Code to reproduce issue:

Code: Select all

private void Form1_Load(object sender, EventArgs e)
      {
         TChart chart = new TChart();
         chart.Parent = this;

         chart.Legend.Visible = false; // !

         DataTable dt = new DataTable("tab1");
         dt.Columns.Add("X", typeof(double));
         dt.Columns.Add("Y", typeof(double));
         dt.Rows.Add(1d, 100d);
         dt.Rows.Add(2d, 20d);

         //Line s = new Line();  // Line is OK
         Area s = new Area();    // Area with s.Color = Color.Green and chart.Legend.Visible = false crashes !

         s.Color = Color.Green;  // !

         s.XValues.DataMember = "X";
         s.YValues.DataMember = "Y";

         s.DataSource = dt;

         chart.Series.Add(s);
      }
Exception stack trace:

Code: Select all

   w Steema.TeeChart.Styles.Custom.DrawPoint(Boolean drawOldPointer, Int32 valueIndex, Int32 x, Int32 y)
   w Steema.TeeChart.Styles.Custom.DrawValue(Int32 valueIndex)
   w Steema.TeeChart.Styles.Custom.DoDrawIndex(Int32 Index, Boolean CanID)
   w Steema.TeeChart.Styles.Series.Draw()
   w Steema.TeeChart.Styles.Custom.Draw()
   w Steema.TeeChart.Styles.Series.DrawSeries()
   w Steema.TeeChart.Chart.DoDraw(Graphics3D g, Int32 First, Int32 Last, Int32 Inc)
   w Steema.TeeChart.Chart.DrawAllSeries(Graphics3D g)
   w Steema.TeeChart.Chart.InternalDraw(Graphics g, Boolean noTools)
   w Steema.TeeChart.Chart.InternalDraw(Graphics g)
   w Steema.TeeChart.TChart.Draw(Graphics g)
   w Steema.TeeChart.TChart.OnPaint(PaintEventArgs pe)
   w System.Windows.Forms.Control.PaintWithErrorHandling(PaintEventArgs e, Int16 layer)
   w System.Windows.Forms.Control.WmPaint(Message& m)
   w System.Windows.Forms.Control.WndProc(Message& m)
   w System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)

Re: Area series with color crashes when legend is invisible

Posted: Thu Jun 05, 2014 11:19 am
by Christopher
MTh wrote:I have TeeChart 4.1.2013.11082 for .Net WinForms.
When I want to use Area series with my own color on chart with hidden legend then it crashes with NullReferenceException.
I've been able to reproduce this issue here and will attempt to fix it before the next maintenance release. In the meantime, the workaround is:

Code: Select all

    private void InitializeChart()
    {
      //tChart1.Parent = this;

      tChart1.Legend.Visible = false; // !

      DataTable dt = new DataTable("tab1");
      dt.Columns.Add("X", typeof(double));
      dt.Columns.Add("Y", typeof(double));
      dt.Rows.Add(1d, 100d);
      dt.Rows.Add(2d, 20d);

      //Line s = new Line();  // Line is OK
      Area s = new Area(tChart1.Chart);  //instead of Area s = new Area() // Area with s.Color = Color.Green and chart.Legend.Visible = false crashes !

      s.Color = Color.Green;  // !

      s.XValues.DataMember = "X";
      s.YValues.DataMember = "Y";

      s.DataSource = dt;

      //tChart1.Series.Add(s);
    }