Can't get SVG to work in v7 (urgent)

TeeChart VCL for Borland/CodeGear/Embarcadero RAD Studio, Delphi and C++ Builder.
Post Reply
pdprog
Newbie
Newbie
Posts: 10
Joined: Fri Jun 25, 2004 4:00 am

Can't get SVG to work in v7 (urgent)

Post by pdprog » Fri Jun 25, 2004 3:57 pm

Hi there... with any luck, I can resolve this before my demo in one hour :-)

I just downloaded the latest TeeChart 7 for D6. (with source, though I
haven't installed that yet)

I updated to get the SVG output. I can't get it to work. :-(

There doesn't seem to be any documention on how to use it, so I copied the
code from aGIFExport.

Code: Select all

    aSVGExport := TSVGExportFormat.Create;
    aSVGExport.Panel := aChart;
    aSVGExport.SaveToFile('c:\temp\Chart1SVG.' + aSVGExport.FileExtension);
    aSVGExport.Free;
This is from a web server application, so there is no TWinControl around.
When SaveToFile() is called, I get an exception that the control has no
parentControl. I presume it is talking about the "aChart" control.

Note: The next line in the code, that I've been using 'till now,
is:

Code: Select all

    aChart.SaveToBitmapFile( aPhysicalFileName );
This one works fine.

Suggestions?

Thanks,

-pete

Marjan
Site Admin
Site Admin
Posts: 745
Joined: Fri Nov 07, 2003 5:00 am
Location: Slovenia
Contact:

Post by Marjan » Fri Jun 25, 2004 5:14 pm

Hi.

A quick workoarund (if possible) would be to create a temporary TWincontrol (panle, form, ...), then create a aChart with it's owner set to TWinControl and then call the SVG export code you've been using.
Marjan Slatinek,
http://www.steema.com

pdprog
Newbie
Newbie
Posts: 10
Joined: Fri Jun 25, 2004 4:00 am

I'll give that a try.

Post by pdprog » Fri Jun 25, 2004 6:21 pm

Thanks. I'll give that a try.
Is this a bug, or by design? (i.e. are most of your users creating desktop apps?)
Do you need a beta tester for internet app functionality?

pdprog
Newbie
Newbie
Posts: 10
Joined: Fri Jun 25, 2004 4:00 am

Still not working

Post by pdprog » Fri Jun 25, 2004 6:38 pm

I've tried this two ways and can't get either to work

Method 1:

Code: Select all

aWinControl := TWinControl.Create( self );
aChart  := TChart.Create( aWinControl );
aChart.Parent := aWinControl;
<setup chart here>
TeeSaveToSVGFile( aChart, 'c:\temp\chart1svg.svg', 500, 400 );
Result:
Control '' has no parent window


Method 2:

Code: Select all

aWinControl := TWinControl.Create( self );
aChart  := TChart.Create( aWinControl );
aChart.Parent := aWinControl;
<setup chart here>
aSVGExport := TSVGExportFormat.Create;
aSVGExport.Panel := aChart;
aSVGExport.SaveToFile('c:\temp\Chart1SVG.' +  aSVGExport.FileExtension);
Result:
Canvas does not allow drawing


More thoughts? Demo is over, but I still need to get this working.

Thanks for your quick initial response :D

Marjan
Site Admin
Site Admin
Posts: 745
Joined: Fri Nov 07, 2003 5:00 am
Location: Slovenia
Contact:

Post by Marjan » Thu Jul 01, 2004 5:32 pm

Hi.

It appears the vector export formats (EPS, PDF, VML and SVG) all have this problem. For "normal" bitmaps the code I sent you work fine, but for vector formats it fails. I think the problem is vector formats cannot use internal buffer and therefore the internal buffer canvas handle is set to nil. A fix seems to be to enable buffered display if chart has no parent. We'll test this and if it works fine include it in next maintenance release.
Last edited by Marjan on Thu Jul 01, 2004 5:42 pm, edited 1 time in total.
Marjan Slatinek,
http://www.steema.com

Marjan
Site Admin
Site Admin
Posts: 745
Joined: Fri Nov 07, 2003 5:00 am
Location: Slovenia
Contact:

Post by Marjan » Thu Jul 01, 2004 5:38 pm

Hi.

After some testing, it appears the following code works fine. The TPanel still needs a parent, but it can be any valid object (I think):

Code: Select all

var tp: TPanel;
    aChart: TChart;
begin
  tp := TPanel.Create(Self);
  try
    tp.Parent:=Self;
    aChart := TChart.Create(nil);
    try
      aChart.Parent := tp;
      With TSVGExportFormat.Create do
      try
        Panel := aChart;
        Width := 300;
        Height := 200;
        SaveToFile('d:\temp\test.svg');
      finally
        Free;
      end;
    finally
      aChart.Free;
    end;
  finally
    tp.Free;
  end;
end;
Marjan Slatinek,
http://www.steema.com

pdprog
Newbie
Newbie
Posts: 10
Joined: Fri Jun 25, 2004 4:00 am

nope

Post by pdprog » Fri Jul 02, 2004 12:19 am

Have you tried this in a non-windowed app?

It seems to follow my "parent" heierarchy up quite a ways to determine that my final object doesn't have a parent window!

-pete

David Berneda
Site Admin
Site Admin
Posts: 83
Joined: Wed Nov 12, 2003 5:00 am
Location: Girona, Catalonia
Contact:

Post by David Berneda » Fri Jul 02, 2004 3:20 pm

Hi Pete
This is an VCL limitation (the canvas class only works fine when the control has a parent, and this parent ultimately has a form parent).

To overcome this, the only (easy) workaround is to modify TeeChart source code. I've already applied the fix for next coming version 7.01 (free upgrade).

So, open and edit the TeeSVGCanvas.pas unit, replacing the method below.

The important (newly added) lines are these:

Code: Select all

      if not Assigned(Panel.Parent) then
         Panel.BufferedDisplay:=True;  // 7.01

You can use the "TeeRecompile.exe" executable to automatically recompile all the packages and to install them at Delphi 6.

TeeRecompile.exe is included with TeeChart Pro v7 source code installer.

Basically, the fix is to re-enable double-buffering on TChart Canvas when there is no Chart Parent.
When double-buffering is on, the canvas used is an internal TBitmap.Canvas instead of the limited TChart.Canvas. TBitmap canvases do not seem to suffer from this limitation.

regards
david

Code: Select all

function TSVGExportFormat.SVG: TStringList;
var tmp : TCanvas3D;
begin { return a panel or chart in SVG format into a StringList }
  CheckSize;

  result:=TStringList.Create;
  Panel.AutoRepaint:=False;
  try

    tmp:=Panel.Canvas;

    {$IFNDEF CLR}  // Protected across assemblies
    TTeePanelAccess(Panel).InternalCanvas:=nil;
    {$ENDIF}

    CheckProperties; // 7.01
    
    Panel.Canvas:=TSVGCanvas.Create(result);
    try
      Panel.Canvas.Assign(tmp);

      if not Assigned(Panel.Parent) then
         Panel.BufferedDisplay:=True;  // 7.01

      TSVGCanvas(Panel.Canvas).Antialias:=FProperties.CBAntiAlias.Checked;

      Panel.Draw(Panel.Canvas.ReferenceCanvas,TeeRect(0,0,Width,Height));
    finally
      Panel.Canvas:=tmp;
    end;

  finally
    Panel.AutoRepaint:=True;
  end;
end;

pdprog
Newbie
Newbie
Posts: 10
Joined: Fri Jun 25, 2004 4:00 am

Post by pdprog » Fri Jul 02, 2004 9:46 pm

That source change worked fine. Thanks.

Post Reply