Recent

Author Topic: userdefinedchartsource updates when a different userdefinedchartsource is reset  (Read 2410 times)

acp693

  • Jr. Member
  • **
  • Posts: 59
Hi,

I was having difficulties in my project with chart sources updating without calling reset.

To test it I created the following simple project

I placed a TChart with two line series and a button on a form and set up two UserDefinedchartSources and linked them to the chart.
I set up two arrays to hold 5 datapoints each and allocated some data to them.
then called UserdefindChartSource.reset for each chartsource in the Form1.OnShow event.
The code for the button changes one datapoint in both arrays, Then only UserdefinedChartSource1.reset is called. Both chart series update even though userdefinedchartsource2.reset isn't called at all.
If I comment out the line UserDefinedChartsource1.reset in the button1.click event nothing gets updated.

This seems like a bug to me, should I report it to bugtracker? Thanks.

Code: [Select]
unit Unit1;

{$mode objfpc}{$H+}

interface

uses
  Classes, SysUtils, FileUtil, TAGraph, TASources, TASeries, Forms, Controls,
  Graphics, Dialogs, StdCtrls, TACustomSource;

type

  { TForm1 }

  TForm1 = class(TForm)
    Button1: TButton;
    Chart1: TChart;
    Chart1LineSeries1: TLineSeries;
    Chart1LineSeries2: TLineSeries;
    UserDefinedChartSource1: TUserDefinedChartSource;
    UserDefinedChartSource2: TUserDefinedChartSource;
    procedure Button1Click(Sender: TObject);
    procedure FormShow(Sender: TObject);
    procedure UserDefinedChartSource1GetChartDataItem(
      ASource: TUserDefinedChartSource; AIndex: Integer;
      var AItem: TChartDataItem);
    procedure UserDefinedChartSource2GetChartDataItem(
      ASource: TUserDefinedChartSource; AIndex: Integer;
      var AItem: TChartDataItem);
  private
    { private declarations }
  public
    { public declarations }
  end;

var
  Form1: TForm1;
  series1data: array[0..4] of integer;
  series2data: array[0..4] of integer;

implementation

{$R *.lfm}

{ TForm1 }

procedure TForm1.UserDefinedChartSource2GetChartDataItem(
  ASource: TUserDefinedChartSource; AIndex: Integer; var AItem: TChartDataItem);
begin
    aItem.x:= AIndex;
    aItem.y:= series2Data[AIndex];

end;

procedure TForm1.UserDefinedChartSource1GetChartDataItem(
  ASource: TUserDefinedChartSource; AIndex: Integer; var AItem: TChartDataItem);
begin
    aItem.x:= AIndex;
    aItem.y:= series1Data[AIndex];
end;

procedure TForm1.FormShow(Sender: TObject);
var
  i:integer;
begin
    series1data[0]:= 1;
    series1data[1]:= 2;
    series1data[2]:= 4;
    series1data[3]:= 2;
    series1data[4]:= 0;
    series2data[0]:= 3;
    series2data[1]:= 2;
    series2data[2]:= 0;
    series2data[3]:= 2;
    series2data[4]:= 4;
    userdefinedchartsource1.Reset ;
    userdefinedchartsource2.Reset ;
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
      series1data[0]:= 2;
      series2data[0]:= 0;
      userdefinedchartsource1.Reset ; // Only one trace is reset, but both traces update on the chart.
end;

end.
                                                               

wp

  • Hero Member
  • *****
  • Posts: 6301
In my opinion this is caused by the redraw of the chart initiated by UserDefinedChartSource1.Reset in Button1Click; probably you would have the same effect even without Reset if you resize the window (the chart must be client-aligned for enforcing a redraw this way), or call Chart.Refresh in Button1Click. Whenever the chart is redrawn the current data values are passed to the series. Reset, on the other hand, is necessary to update calculation of axis limits, for examples.

In order to have a closer look could you please pack the form1.pas, form1.lfm, project1.lpr, and project.lpi files of your demo into a zip archive and upload it.
Lazarus trunk / fpc 3.0.4 / all 32-bit on Win-10

acp693

  • Jr. Member
  • **
  • Posts: 59
Thanks for the reply. Maybe I've simply misunderstood the userdefinedChartsource. Yes indeed, resizing causes the charts to update. In any case here's the zipped project.

Best regards

Albert

wp

  • Hero Member
  • *****
  • Posts: 6301
Yes, your project behaves like I described in the previous posting. Definitely no bug.
Lazarus trunk / fpc 3.0.4 / all 32-bit on Win-10