Page 1 of 1

Deleting mouse selected data ?

Posted: Tue Nov 13, 2007 1:16 pm
by 9349911
Hi support,

a customer asked me the following and I can´t find an answer ...

Is it possible to select an x-area of the chart with the mouse and then delete the data I´ve selected?

Example ...
I have a chart with 2 fastline series. The X axis has values from 0 to 50.
I select the data from X value 0 to 20 and delete it.
After this procedure the X axis shows only the vales from 20 to 50. And the data from the both fastlines only have 30 x/y values.

Posted: Tue Nov 13, 2007 2:46 pm
by narcis
Hi Dominik,

Yes, you could use a TColorBandTool for selecting the values as some code like this:

Code: Select all

procedure TForm1.FormCreate(Sender: TObject);
begin
  Series1.FillSampleValues(50);
  Series2.FillSampleValues(50);

  ChartTool1.Axis:=Series1.GetHorizAxis;
  ChartTool1.StartLine.AllowDrag:=true;
  ChartTool1.StartLine.Active:=true;
  ChartTool1.EndLine.AllowDrag:=true;
  ChartTool1.EndLine.Active:=true;

  ChartTool1.StartValue:=5;
  ChartTool1.EndValue:=25;
end;

procedure TForm1.Button1Click(Sender: TObject);
var i: integer;
    tmp: double;
begin
  for i:=Series1.Count-1 downto 0 do
  begin
    tmp:=Series1.XValue[i];

    if ((tmp>=ChartTool1.StartValue) and (tmp<=ChartTool1.EndValue)) then
    begin
      Series1.Delete(i);
      Series2.Delete(i);
    end;
  end;
end;

Posted: Wed Nov 14, 2007 8:18 am
by 9349911
Hi Narcis,

I did a test today and it works nearly perfect.

I have only one problem left ...
Is it possible to recalculate the X Axis?

Example:
If I delete the data from XValue 0 - 20 the x axis starts from 21 after deleting. But it would be better if the Axis starts from 0 again.

Same problem if I delete values from 10-20 for example. Only the Y data is deleted and not the x values.

I can make two pictures is necessary.

Posted: Wed Nov 14, 2007 9:26 am
by narcis
Hi Dominik,

Ok, then the solution is pretty easy. You can force sequential values in series using FillSequence as shown here:

Code: Select all

procedure TForm1.Button1Click(Sender: TObject);
var i: integer;
    tmp: double;
begin
  for i:=Series1.Count-1 downto 0 do
  begin
    tmp:=Series1.XValue[i];

    if ((tmp>=ChartTool1.StartValue) and (tmp<=ChartTool1.EndValue)) then
    begin
      Series1.Delete(i);
      Series2.Delete(i);
    end;
  end;

  Series1.XValues.FillSequence;
  Series2.XValues.FillSequence;
end;

Posted: Wed Nov 14, 2007 9:32 am
by 9349911
Hi Narcis,

I´m speechless, really !

There is actually no day (until we bought TChart) where I don´t found any amazing feature in TChart.

Thx alot for your help !!!

Image

Posted: Wed Nov 14, 2007 9:48 am
by narcis
Hi Dominik,

You're very welcome! I'm glad to hear that.