Page 1 of 1

Can I only export active series to a text file.

Posted: Wed Jul 25, 2012 8:16 am
by 10049371
Hello,

I'm using the TSeriesDataText to export the data to a text (csv) file. The user can activate and de-activate the series and wants only the active series to be exported.
I noticed that all the series (active and de-active) are exported to the text file.

Is there a way to only export the active series.

Thanks in advance.

Marcel

Re: Can I only export active series to a text file.

Posted: Thu Jul 26, 2012 9:31 am
by yeray
Hi Marcel,
MarcelIbis wrote:Is there a way to only export the active series.
I'm afraid not. However you can always do you own exportation method.

Re: Can I only export active series to a text file.

Posted: Mon Jul 30, 2012 8:47 am
by 10049371
Hello Yeray,

Thanks for your reply.

I noticed that in the TChartEditor component you have the oportunity to select all sereies or select one serie (see tab Export, Data).
Can this code not be used to add only the active series to the TSeriesDataText component?

If yes, do you have an example how to add series to the TSeriesData component?

I noticed also that the help file Tchart8.hlp is (very) old. Is there a new version available?

Thanks in advance.

Marcel

Re: Can I only export active series to a text file.

Posted: Tue Jul 31, 2012 8:39 am
by yeray
Hi Marcel,
MarcelIbis wrote:I noticed that in the TChartEditor component you have the oportunity to select all sereies or select one serie (see tab Export, Data).
Can this code not be used to add only the active series to the TSeriesDataText component?
I'm afraid not. This is how it's made in TeeStore:

Code: Select all

  if Assigned(Series) then
     DoSeries(Series)
  else
  for t:=0 to Chart.SeriesCount-1 do
      DoSeries(Chart[t]);
Changing the code above for this works as you wish:

Code: Select all

  if Assigned(Series) then
     DoSeries(Series)
  else
  for t:=0 to Chart.SeriesCount-1 do
      if Chart[t].Active then DoSeries(Chart[t]);
But applying this change would break the backwards compatibility. So we should probably add a boolean to control if the Chart[t].Active should be considered or not (not by default, as always).
I've added it to the wish list.
MarcelIbis wrote:I noticed also that the help file Tchart8.hlp is (very) old. Is there a new version available?
Do you see this file in an actual installation of TeeChart VCL v2012.06? I can only find a TeeChart2012.hlp in the Docs folder into the TeeChart installation.

Re: Can I only export active series to a text file.

Posted: Tue Jul 31, 2012 9:16 am
by yeray
Hi Marcel,

Alternativelly, we could make the Series property in TSeriesDataText to accept an array of series. This would allow the user to export only the desired series. This would be more flexible.

Re: Can I only export active series to a text file.

Posted: Wed Aug 01, 2012 12:52 pm
by 10049371
Hello Yeray

Thank you for your suggestions to improve the export function.

For the time being I use the following workarround:
I delete the non active series before the export as shown below.
Than create the series again.

for i := Chart.SeriesList.Count -1 downto 0 do begin
if not Chart.Series.Active then
Chart.Series.Free;
end;

ExcelData := TSeriesDataText.Create(Chart, nil);
try
ExcelData.TextDelimiter := ';';
ExcelData.IncludeLabels := True;
ExcelData.IncludeHeader := True;
ExcelData.ValueFormat := '0.000 E+0';

ExcelData.SaveToFile(Datafile);

finally
ExcelData.Free;
end;

MakeSeries.

Regards,

Marcel

Re: Can I only export active series to a text file.

Posted: Wed Aug 01, 2012 1:36 pm
by yeray
Hi Marcel,

Right. And instead of removing and recreating the inactive series, you could move them into a temporal list and restore them after exporting the series.
Here it is an example.
However, if you want the order of the series to be maintained, you should improve it.

Code: Select all

uses Series, TeeStore;

procedure TForm1.FormCreate(Sender: TObject);
var i, j: Integer;
begin
  Chart1.View3D:=false;
  Chart1.Legend.CheckBoxes:=true;

  for i:=0 to 5 do
    with Chart1.AddSeries(TBarSeries) do
    begin
      Title:='Series nº' + IntToStr(i+1);
      Color:=OperaPalette[i mod Length(OperaPalette)];
      Marks.Style:=smsValue;
      Active:=(i mod 2 = 0);

      for j:=0 to 5 do
        Add(random*75+25, 'Value nº ' + IntToStr(j+1));
    end;
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
  ExportActiveSeries;
end;

procedure TForm1.ExportActiveSeries;
var i: Integer;
    tmpSeriesList: TChartSeriesList;
begin
  tmpSeriesList:=TChartSeriesList.Create;

  for i:=Chart1.SeriesCount-1 downto 0 do
  begin
    if not Chart1[i].Active then
    begin
      tmpSeriesList.Add(Chart1[i]);
      Chart1[i].ParentChart:=nil;
    end;
  end;

  with TSeriesDataText.Create(Chart1) do
  begin
    IncludeHeader:=true;
    IncludeLabels:=true;
    ValueFormat:='0.000 E+0';
    TextDelimiter:=';';
    SaveToFile('C:\tmp\testExport.csv');
  end;

  for i:=tmpSeriesList.Count-1 downto 0 do
  begin
    tmpSeriesList[i].ParentChart:=Chart1;
  end;
end;

Re: Can I only export active series to a text file.

Posted: Wed Aug 01, 2012 3:15 pm
by 10049371
Hello Yeray

Your workarround works great. :D
Saves time to create and fill the series again!

One minor detail, I had to include the TeEngine unit in the uses clause for version 8.

Thanks for the grear service.

Regards,

Marcel

Re: Can I only export active series to a text file.

Posted: Thu Aug 02, 2012 10:48 am
by yeray
Hi Marcel,

I'm glad to hear it works and you like it! :)

Re: Can I only export active series to a text file.

Posted: Tue Dec 03, 2013 2:30 pm
by David
A new property in TSeriesData class has been introduced to allow exporting only a selected list of Series.

http://bugs.teechart.net/show_bug.cgi?id=243

This wish has been implemented, at the base class TSeriesData (TeeStore.pas unit), so all derived export format classes now have a new property (an array of Series) to filter which Series should be exported.

This applies to TSeriesDataText (txt, csv), TSeriesDataXML (xml), TSeriesDataHTML (html <table>), TSeriesDataXLS (Excel) and TSeriesDataJSON (json).

Usage example:

uses TeeStore;

procedure TForm1.FormCreate(Sender: TObject);
var data : TSeriesDataText;
begin
data:=TSeriesDataText.Create(Chart1);

data.IncludeHeader:=True;

data.SeriesList.Clear;

// Add only the Series you want to export:

data.SeriesList.Add(Series3);
data.SeriesList.Add(Series5);
data.SeriesList.Add(Series6);

Memo1.Text:=data.AsString;

data.Free;
end;

Re: Can I only export active series to a text file.

Posted: Wed Dec 04, 2013 11:59 am
by 10049371
Hello David,

Great! Thanks for this update.
Could every wish of me being solved this way. :wink:

In which version is this implemented?

Regards,

Marcel Horsthuis.

Re: Can I only export active series to a text file.

Posted: Mon Dec 09, 2013 12:09 pm
by narcis
Hi Marcel,
MarcelIbis wrote: In which version is this implemented?
Not a public version yet but the next maintenance release. It will be announced in this forum and other Steema Software channels as well.