Solved

TChart in a webapplication?

Posted on 2002-07-15
11
501 Views
Last Modified: 2010-04-04
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
Comment
Question by:corpa
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 4
  • 2
  • +1
11 Comments
 
LVL 2

Expert Comment

by:mikepj
ID: 7155916
Why not just use 0 (or nil) instead of the handle?
0
 

Author Comment

by:corpa
ID: 7156487
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
 
LVL 17

Expert Comment

by:geobul
ID: 7156538
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!

 
LVL 2

Expert Comment

by:mikepj
ID: 7157179
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
 

Author Comment

by:corpa
ID: 7157516
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
 

Expert Comment

by:RayNorrish
ID: 7172153
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
 

Expert Comment

by:RayNorrish
ID: 7172164
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
 

Author Comment

by:corpa
ID: 7175902
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
 

Expert Comment

by:RayNorrish
ID: 7176568
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
 

Accepted Solution

by:
RayNorrish earned 100 total points
ID: 7176611
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
 

Author Comment

by:corpa
ID: 7177313
Excellent, this is exact what I needed and it works just perfect. Thanks alot, all credits go to you.

Corpa
0

Featured Post

Technology Partners: 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!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
Michael from AdRem Software outlines event notifications and Automatic Corrective Actions in network monitoring. Automatic Corrective Actions are scripts, which can automatically run upon discovery of a certain undesirable condition in your network.…
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …

688 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question