Solved

TChart in a webapplication?

Posted on 2002-07-15
11
482 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
  • 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
 
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
Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 

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

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

Suggested Solutions

Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

759 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now