Caves Travel Diving Graphics Mizar Texts Cuisine Lemkov Contact Map RSS Polski
Trybiks' Dive Texts Intraweb Using TChart with Intraweb YAC Software
  Back

List

Charsets

Charts

DBExpress

Delphi

HTML

Intraweb

MSTest

PHP

Programming

R

Rhino Mocks

Software

Testing

UI Testing

VB.NET

VCL

WPF

Using TChart with Intraweb
Let's say that you have an Intraweb (VCL for the Web) application. And you want to display in it some charts. One of the possible solutions is to use the standard TChart component distributed with Delphi:
  • create a TChart in the background; add series and results
  • save the TChart to a graphics file
  • display that file with the standard HTML - IMG
The code is pretty simple:
  var
    LImage: TGraphic;
  . . .
  // GetChartFileName creates a file name for your chart - more about this below:
  LImageFileName := GetChartFileName;
  ForceDirectories(ExtractFilePath(LImageFileName));
  // Create a bitmap that will
  LBitmap := TBitmap.Create;
  try
    // We don't want any distortions when saving the chart's image:
    LBitmap.SetSize(Chart.Width, Chart.Height);
    LRect := Rect(0, 0, Chart.Width, Chart.Height);
    Chart.Draw(LBitmap.Canvas, LRect);
    LImage := TGIFImage.Create;
    try
      LImage.Assign(LBitmap);
      LImage.SaveToFile(LImageFileName);
    finally
      FreeAndNIL(LImage);
    end;
  finally
    FreeAndNIL(LBitmap);
  end;
Now, you can refer to this file using a template page (and an IW layout manager) with an IMG tag. Or you can use IW's TIWImageFile component:
  ChartImageFile.ImageFile.FileName := GetChartFileName;
  ChartImageFile.OutputType := ioGIF;
The above code handled GIF images; however, if you're using complex shading, background images, etc. you may want to change to JPEG images:
  // In the first code snippet:
    LImage := TJPEGImage.Create;
  . . .
  // In the second code snippet:
  ChartImageFile.OutputType := ioJPEG;
Note that TJPEGImage handles compression levels (CompressionQuality) - you may want to experiment with that.

Earlier, I wrote that GetChartFileName needs some more discussion:
  • First, chart files must be created in the ./Files subfolder (or any subfolder there).
  • Second, a chart's file name may need to be unique for different sessions. If this is the case in your program, you can easily generate such names by appending the session's ID to the chart's file name.
Anyway, a pretty quick and easy way to display charts in Intraweb applications.

Top

Comments
Alas!
No comments yet...

Top

Add a comment (fields with an asterisk are required)
Name / nick *
Mail (will remain hidden) *
Your website
Comment (no tags) *
Enter the text displayed below *
 

Top

Tags

Intraweb

Charts

Delphi


Related pages

Delphi interfaces... again

Checking "Dangling" Event Handlers in Delphi Forms

Drag-n-drop files onto the application window

Intraweb and MaxConnections

A Case for FreeAndNIL

Intraweb as an Apache DSO module

"Device not supported" in Intraweb

Automated GUI Testing

Rounding and precision on the 8087 FPU

SessionTimeout in Intraweb

Unknown driver: MySQL

TIdMessage's CharSet

Software Guarantees

Automated Testing of Window Forms

TChart - Missing Labels in Axes

Memory Leaks and Connection Explosions in DBExpress

Controlling Conditional Defines and Compilation Switches

Detecting Memory Leaks with DUnit

last_insert_id() and DBExpress

Registering Extensions

DBExpress and Thread Safety

Forms as Frames

Checking Dangling Pointers vs. the New Memory Manager

</form> ... <form>

Accessing Protected Members

Objects, interfaces, and memory management in Delphi