CGDevTools Forum

Welcome to the Official CGDevTools Support Community Forums.

Uncaught TypeError

by etwoss » 14 Jul 2014 13:56

Hi

I have forms using the JQPlot component.
Sometimes i get the error (on first show of the form):
Uncaught TypeError: Cannot read property 'redraw' of null


Any idea what going on?
Result is that my form does not resize properly, so the event flow is broking, i think

Eric
etwoss
 
Posts: 1205
Joined: 06 Feb 2014 08:58

by Alexander Bulei » 14 Jul 2014 14:06

Hi etwoss,

Sometimes i get the error (on first show of the form):


Can you replicate it in simple testcase?
Do you call some plugin method?

Best Regards.
Group: Developers | Support Team

  • info [at] cgdevtools.com - General information
  • sales [at] cgdevtools.com - Sales department
  • support [at] cgdevtools.com - Product and Technical Support
User avatar
Alexander Bulei
Site Admin
 
Posts: 3635
Joined: 15 May 2012 08:52
Location: Mealhada, Portugal

by etwoss » 14 Jul 2014 14:18

Hi

I think diffecult to replicate

My Code:

Code: Select all
      PlotData:= SA([]);
      LayerData:= SA([]);

      for i := 0 to ValueList.Count - 1 do
      begin
        SerieData:= SA([]);
        SerieData.AsArray.Add(SO(Copy(ValueList.Names[i], Pos('_',ValueList.Names[i]) + 1, Length(ValueList.Names[i]))));
        SerieData.AsArray.Add(SO(ValueList.ValueFromIndex[i]));
        LayerData.AsArray.Add(SerieData);
      end;

      PlotData.AsArray.Add(LayerData);

      AChart.JQPlotData := PlotData.AsJSon;
      AChart.Redraw(True);
    end;
  finally
    FreeAndNil(ValueList);
  end;


Changed it to:

Code: Select all
    if (ValueList.Count > 0) then
    begin
      PlotData:= SA([]);
      LayerData:= SA([]);

      for i := 0 to ValueList.Count - 1 do
      begin
        SerieData:= SA([]);
        SerieData.AsArray.Add(SO(Copy(ValueList.Names[i], Pos('_',ValueList.Names[i]) + 1, Length(ValueList.Names[i]))));
        SerieData.AsArray.Add(SO(ValueList.ValueFromIndex[i]));
        LayerData.AsArray.Add(SerieData);
      end;

      PlotData.AsArray.Add(LayerData);

      AChart.JQPlotData := PlotData.AsJSon;
      try
        AChart.Redraw(True);
      except
        // Sometimes Uncaught TypeError: Cannot read property 'redraw' of null
      end;
    end;
  finally
    FreeAndNil(ValueList);
  end;


Eric
etwoss
 
Posts: 1205
Joined: 06 Feb 2014 08:58

by Alexander Bulei » 14 Jul 2014 17:01

Hi Eric,

Where are you calling this code?

Best Regards.
Group: Developers | Support Team

  • info [at] cgdevtools.com - General information
  • sales [at] cgdevtools.com - Sales department
  • support [at] cgdevtools.com - Product and Technical Support
User avatar
Alexander Bulei
Site Admin
 
Posts: 3635
Joined: 15 May 2012 08:52
Location: Mealhada, Portugal

by etwoss » 15 Jul 2014 08:34

Hi

I have my own method, which is called after the Show of the form

Code: Select all
procedure FillTimelineCG(AChart: TIWCGJQPlot;
                         ATable: TADODataset;
                         APeriodProperty,
                         AValue1Property,
                         ACaption1,
                         AValue2Property,
                         ACaption2,
                         AHint: String;
                         Animate: Boolean);


const
  Months : array[1..12] of string = ('Jan','Feb','Mar','Apr','May','Jun','Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec');

var
  PeriodField: TField;
  Value1Field: TField;
  i: Integer;
  Serie: TIWCGJQPlotOptionsSeriesDefaults;
  Axis: TIWCGJQPlotOptionsAxesItem;
  ThisDate: TDateTime;
  StartDate: TDateTime;
  NrOfMonths: Integer;
  ValueList : TStringList;
  yy, mm, dd: Word;
  AIndex: Integer;
  PlotData: ISuperObject;
  LayerData: ISuperObject;
  SerieData: ISuperObject;
  TimelinePeriod: Integer;

begin
  AChart.JQPlotOptions.SeriesDefaults.Renderer := jqprBarRenderer;
  AChart.JQPlotOptions.SeriesDefaults.BarRendererOptions.FillToZero := True;
  AChart.JQPlotOptions.SeriesDefaults.BarRendererOptions.ShowTooltipUnitPosition:= True;
  AChart.JQPlotOptions.SeriesDefaults.Color := ColorToCGColor(IWServerController.ReadSetting('WebColor', WEB_COLOR));

  if (Animate) then
  begin
    AChart.JQPlotOptions.Animate := True;
    AChart.JQPlotOptions.AnimateReplot := True;
  end;
  AChart.Hint := AHint;

  TimelinePeriod := IWServerController.ReadSetting('TimelinePeriod', TIMELINE_PERIOD);

  case TimelinePeriod of
    1,2,3 : AChart.JQPlotOptions.SeriesDefaults.BarRendererOptions.BarWidth := 30;
    4,5,6 : AChart.JQPlotOptions.SeriesDefaults.BarRendererOptions.BarWidth := 25;
    7,8,9 : AChart.JQPlotOptions.SeriesDefaults.BarRendererOptions.BarWidth := 20;
  else
    AChart.JQPlotOptions.SeriesDefaults.BarRendererOptions.BarWidth := 15;
  end;


  PeriodField := ATable.FieldByName(APeriodProperty);
  if (PeriodField = nil) then
    raise Exception.Create('Period field ' + APeriodProperty + ' not found in UDQ.');

  Value1Field := ATable.FieldByName(AValue1Property);
  if (Value1Field = nil) then
    raise Exception.Create(LogError('Value field ' + AValue1Property + ' not found in UDQ.'));

  Serie:= AChart.JQPlotOptions.Series.Add;
  Serie.Label_:= ACaption1;

  StartDate  := IWServerController.GlobalPeriodStart;

  NrOfMonths := IWServerController.ReadSetting('TimelinePeriod', TIMELINE_PERIOD) - 1;

  Axis:= AChart.JQPlotOptions.Axes.Add;
  Axis.Options.AxesRender:= jqparCategoryAxisRenderer;

  ValueList := TStringList.Create;
  try
    ValueList.Add(Format('%s=%d',[FormatDateTime('YYYYMM_MMM',StartDate),0]));

    DecodeDate(StartDate, yy, mm, dd);
    StartDate := EncodeDate(yy,mm,1);

    for i := 1 to NrOfMonths do
    begin
      StartDate := IncMonth(StartDate,1);
      ValueList.Add(Format('%s=%d',[FormatDateTime('YYYYMM_MMM',StartDate),0]));
    end;

    ATable.First;
    while (not ATable.Eof) do
    begin
      ThisDate := PeriodField.AsInteger;
      if (DayOfTheMonth(ThisDate) <> 1) then
      begin
        ATable.Next;
        Continue;
      end;

      StartDate := PeriodField.AsInteger;
      AIndex := ValueList.IndexOfName(FormatDateTime('YYYYMM_MMM',StartDate));
      if (AIndex > -1) then
      begin
        ValueList.ValueFromIndex[AIndex] := FloatToStr(
          StrToFloatDef(ValueList.ValueFromIndex[AIndex],0) +
            Value1Field.AsFloat);
      end;
      ATable.Next;
    end;


    if (ValueList.Count > 0) then
    begin
      PlotData:= SA([]);
      LayerData:= SA([]);

      for i := 0 to ValueList.Count - 1 do
      begin
        SerieData:= SA([]);
        SerieData.AsArray.Add(SO(Copy(ValueList.Names[i], Pos('_',ValueList.Names[i]) + 1, Length(ValueList.Names[i]))));
        SerieData.AsArray.Add(SO(ValueList.ValueFromIndex[i]));
        LayerData.AsArray.Add(SerieData);
      end;

      PlotData.AsArray.Add(LayerData);

      AChart.JQPlotData := PlotData.AsJSon;
      try
        AChart.Redraw(True);
      except
        // Sometimes Uncaught TypeError: Cannot read property 'redraw' of null
      end;
    end;
  finally
    FreeAndNil(ValueList);
  end;

end;

etwoss
 
Posts: 1205
Joined: 06 Feb 2014 08:58

by Alexander Bulei » 15 Jul 2014 09:05

Hi etwoss,

if you have the code in show form, so calling the redraw method doesn't make sense, like calling AjaxReRender OnCreate :?

Best Regards.
Group: Developers | Support Team

  • info [at] cgdevtools.com - General information
  • sales [at] cgdevtools.com - Sales department
  • support [at] cgdevtools.com - Product and Technical Support
User avatar
Alexander Bulei
Site Admin
 
Posts: 3635
Joined: 15 May 2012 08:52
Location: Mealhada, Portugal

by etwoss » 15 Jul 2014 11:07

Hi

Its after the Show as you can see

ShowForm, does create (if not exist) and show the form
The loaddetails does the call

Eric
Code: Select all
   ReportDetailForm := ShowForm(TFormAdminReportDetail) as TFormAdminReportDetail;
    ReportDetailForm.LoadDetail(Parameter,
                                BaseDataCache.Currency,
                                BaseDataCache.BaseTable,
                                BaseDataCache.TimelineTable,
                                ColumnToFilter(grid.JQGridOptions.ColModel[ColIndex].Caption),
                                Parameter,
                                BarNameByReportType(ReportDetail),
                                BarValueByReportType(ReportDetail),
                                TimelineNameByReportType(ReportDetail),
                                TimelineValueByReportType(ReportDetail),
                                BaseDataCache.Timestamp,
                                GroupByByReportType(ReportDetail), '','');
 
etwoss
 
Posts: 1205
Joined: 06 Feb 2014 08:58

by Alexander Bulei » 15 Jul 2014 15:11

Hi etwoss,

Its after the Show as you can see


On same event?

Best Regards.
Group: Developers | Support Team

  • info [at] cgdevtools.com - General information
  • sales [at] cgdevtools.com - Sales department
  • support [at] cgdevtools.com - Product and Technical Support
User avatar
Alexander Bulei
Site Admin
 
Posts: 3635
Joined: 15 May 2012 08:52
Location: Mealhada, Portugal

by etwoss » 17 Jul 2014 10:27

Hi

Yes ( a menuClick)

I checked without the redraw code, seems to work correctly
Gonna do some more tests

Eric
etwoss
 
Posts: 1205
Joined: 06 Feb 2014 08:58


Return to JQPlot

cron

Who is online

Users browsing this forum: No registered users and 4 guests

Contact Us.