• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 518
  • Last Modified:

TChart in a webapplication?

I want to create a TChart inside a webapplication, but the chart needs a Parent Handle wich is usualy a Form.
Since there is no Form in my webapp the chart wont work.
Once the chart is set up I want to save it to a bitmap
-> Chart.SaveToBitmapFile('test.bmp');
so I can set up a link in the Response to the just saved bitmap.
What should be the Parent Handle for the Chart?

Thanks,
Corpa
0
corpa
Asked:
corpa
  • 4
  • 4
  • 2
  • +1
1 Solution
 
mikepjCommented:
Why not just use 0 (or nil) instead of the handle?
0
 
corpaAuthor Commented:
mikepj,

I assigned the NULL but that didn't help.
If I leave the ParentWindow line out it also does not work.
Here's what I got so far:

procedure TWebModule1.WebModule1WebActionItem1Action(Sender: TObject;
  Request: TWebRequest; Response: TWebResponse; var Handled: Boolean);
var val : Integer;
    Gr: TChart;
    Ser: THorizBarSeries;

begin
  Response.Content := '';

  if (Gr <> nil) then Gr.Free;
  Gr := TChart.Create(self);
  Gr.ParentWindow := null;         //this does not work
  if (Ser <> nil) then Ser.Free;
  Ser := THorizBarSeries.Create(self);
  Ser.parentchart := Gr;

  for val := 10 to 50 step 10 do
   Ser.AddBar(val,'anytext', clRed);

  with Gr do
   begin
     width := 420;
     Height :=210;
     Visible := false;
     BevelOuter := bvNone;
     Color := clWhite;
   end;
  Gr.SaveToBitmapFile('chart.bmp');

  Response.Content := Response.Content + 'Hello world';
end;


Any ideas?
0
 
geobulCommented:
Hi,
I'm afraid that you may not use any visual components in CGI/ISAPI applications.

Regards, Geo
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
mikepjCommented:
I think the component is one of those which you can't.  I think the Pro Essentials graph I use can be instantiated with no parent.
0
 
corpaAuthor Commented:
Ok, bad programming from my side.
Now what should I do to reach my target?
I want to be able to create a chart (bitmap) that
changes from content as people submit a html form.
So the bitmap needs to be created inside my webapp.
I already know what to do to get the bitmap displayed in the result page, but creating it and storing seems to be a problem.
Mikepj,you mentioned Pro Essentials graph, what is it and where can I find it?

Thanks, corpa
0
 
RayNorrishCommented:
I use TChart, as well as many other visual components in Web Applications. Remember to remove the ChartF from the autocreate.

This example uses the RX Tools rxGif component, and ODBCExpress connectivity for the example.

I can literally copy and paste a TChart object onto the ChartF form from a test program, and it works fine.

If you cannot gain what you need from this example, it may be easier to send you a small example project

Here is my Chart Action:

procedure TWebModule1.WebModule1chartAction(Sender: TObject;
  Request: TWebRequest; Response: TWebResponse; var Handled: Boolean);
var MemStream: TMemoryStream;
    Gif: TGifImage;
    Bit: TBitmap;
    Text: String;
begin
 Text:=Request.QueryFields.Values['model'];
 ChartF:=TChartF.Create(nil);
 With ChartF.OEQuery1 do begin
  Hdbc:=Hdbc1;
  Open;
 end;
 Bit:=TBitmap.Create;
 Bit:=ChartF.BuildChart(Text);
 Gif:=TGifImage.Create;
 Gif.Assign(Bit);
 Bit.Free;
 MemStream:=TMemoryStream.Create;
 Gif.SavetoStream(MemStream);
 MemStream.Position:=0;
 Response.ContentType:='image/gif';
 Response.ContentStream:=MemStream;
 Response.SendResponse;
 Gif.Free;
 ChartF.Release;
end;

Here is the code on the chart form:

function TChartF.BuildChart(cKind: String):TBitmap;
begin
 if cKind='traffic1' then
  Result:=TrafficChart.TeeCreateBitmap(clWhite,Rect(0,0,400,300));
end;
0
 
RayNorrishCommented:
Oh.. and don`t save out a bmp like that from a web app: what happens when multiple hits occur? Also, you have to grant write access to where you save the bmp...

oh.. and bmp are not supported by browsers or are too big...

Use my streaming example to send images.
Good luck!
0
 
corpaAuthor Commented:
Hi, RayNorrish

you have good points there.
I can see what you are doing in the routine, but don't get it all.
Is ChartF a form you declared earlier?
Maybe you should send the example project; do you need my e-mail adress?

Thanks,
Corpa
0
 
RayNorrishCommented:
Sort of. ChartF is a non autocreate form - created just like any other form!
This is where I drop the TChart object.

What I`ll do is put a small project together for a TChart using random points, avoiding DB issues.

I`ll post a URL where you can download it from, shortly.
0
 
RayNorrishCommented:
OK, I`ve posted an example for you at borland.public.attachments

Once compiled: test it like this:

http://yourserver/cgi-bin/chart.exe?model=traffic1

Note that you could also replace an image tag with this method:

<img src="http://yourserver/cgi-bin/chart.exe?model=traffic1">

Oh.. the news server is forums.borland.com

0
 
corpaAuthor Commented:
Excellent, this is exact what I needed and it works just perfect. Thanks alot, all credits go to you.

Corpa
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

  • 4
  • 4
  • 2
  • +1
Tackle projects and never again get stuck behind a technical roadblock.
Join Now