?
Solved

TChart in a webapplication?

Posted on 2002-07-15
11
Medium Priority
?
507 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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
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 400 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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

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…
Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…
Suggested Courses
Course of the Month8 days, 13 hours left to enroll

765 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