Page 1 of 1

Zoom in aspx webchart using Delphi 2006

Posted: Fri Jul 21, 2006 11:38 am
by 9641716
Hi,

I am testing some of the charting functionality with TeeChart.NET and I have managed to get an ASP.NET website running using Delphi 2006 with some webcharts.

I am having trouble when trying to use the zoomtool though for the charts.

I have translated the code in the zooming example from C# to Delphi and it compiles fine but whenever I try and actually zoom, I get an error message saying words to the effect of "invalid parameter" on the following line in the CheckZoom function...
zoomedState=((Steema.TeeChart.Tools.ZoomTool)wChart.Chart.Tools[0]).SetCurrentZoom(Request,zoomedState);

which I have translated to...
zoomedstate:=Steema.TeeChart.Tools.ZoomTool(wChart.Chart.Tools[0]).SetCurrentZoom(Request,zoomedState);

Are there any working examples of this code in Delphi available or can someone provide me with some insight as to what I'm doing wrong.

On the first call to the CheckZoom function, the ZoomState parameter that is passed to the SetCurrentZoom method is null.

The version of TeeChart I have is
2.0.2306.26231 and since I'm using Delphi 2006, I am only developing for .NETv1.1

Thanks

Posted: Fri Jul 21, 2006 4:16 pm
by narcis
Hi PAG,

First of all, it may be helpful for you to translate C# code into Delphi for .NET using Borland's BabelClient.

That being said, to get the ASP.NET demo zoom example in Delphi .NET working, you should drop a WebChart into a WebForm, add GetChart.aspx to your project and use the code below:

WebForm1.aspx.cs:

Code: Select all

unit WebForm1;

interface

uses
  System.Collections, System.ComponentModel,
  System.Data, System.Drawing, System.Web, System.Web.SessionState,
  System.Web.UI, System.Web.UI.WebControls, System.Web.UI.HtmlControls,
  Steema.TeeChart.Web, Steema.TeeChart.Styles, Steema.TeeChart.Tools,
  System.IO, Steema.TeeChart;

type
  TWebForm1 = class(System.Web.UI.Page)
  {$REGION 'Designer Managed Code'}
  strict private
    procedure InitializeComponent;
  {$ENDREGION}
  strict private
    procedure Page_Load(sender: System.Object; e: System.EventArgs);
  strict protected
    WebChart1: Steema.TeeChart.Web.WebChart;
    ZoomTool1: Steema.TeeChart.Tools.ZoomTool;
    procedure OnInit(e: EventArgs); override;
  private
    { Private Declarations }
    procedure CheckZoom(wChart : WebChart);
  public
    { Public Declarations }
  end;

implementation

{$REGION 'Designer Managed Code'}
/// <summary>
/// Required method for Designer support -- do not modify
/// the contents of this method with the code editor.
/// </summary>
procedure TWebForm1.InitializeComponent;
begin
  Include(Self.Load, Self.Page_Load);
end;
{$ENDREGION}

procedure TWebForm1.Page_Load(sender: System.Object; e: System.EventArgs);
Var
  line: Steema.TeeChart.Styles.Line;
  tmpChart:MemoryStream;
  ch1:Chart;
begin
  ZoomTool1 := ZoomTool.Create;
  ch1 := WebChart1.Chart;
  ch1.Aspect.View3D:=False;
  ch1.Tools.Add(ZoomTool1);
  tmpChart := MemoryStream.Create;
  if (Session['ch1'] = nil) then
  begin
    if (ch1.Series.Count < 2) then
    begin
      ch1.Series.Add(Steema.TeeChart.Styles.Points.Create);
      ch1.Series.Add(Steema.TeeChart.Styles.Points.Create);
    end;
    (Points(ch1.Series[0])).Pointer.Pen.Visible := False;
    (Points(ch1.Series[1])).Pointer.Pen.Color := Color.FromArgb(79, 79, 255);
    ch1.Series[0].Color := Color.FromArgb(255, 199, 26);
    ch1.Series[1].Color := Color.FromArgb(106, 106, 255);
    ch1.Series[0].FillSampleValues(36);
    ch1.Series[1].FillSampleValues(36);
    ch1.Export.Template.Save(tmpChart);
    Session.Add('ch1', tmpChart);
  end
  else
  begin
    tmpChart := (MemoryStream(Session['ch1']));
    tmpChart.Position := 0;
    WebChart1.Chart.Import.Template.Load(tmpChart);
    CheckZoom(WebChart1);
  end;

end;

procedure TWebForm1.CheckZoom(wChart : WebChart);
Var zoomedState: ArrayList;
Begin
  zoomedState := (ArrayList(Session[(wChart.ID + 'Zoomed')]));
  zoomedState := (Steema.TeeChart.Tools.ZoomTool(wChart.Chart.Tools[0])).SetCurrentZoom(Request,
      zoomedState);
  if (zoomedState = nil) then
    Session.Remove((wChart.ID + 'Zoomed'))
  else
    Session.Add((wChart.ID + 'Zoomed'), zoomedState);
End;

procedure TWebForm1.OnInit(e: EventArgs);
begin
  //
  // Required for Designer support
  //
  InitializeComponent;
  inherited OnInit(e);
end;

end.

GetChart.aspx.cs:

Code: Select all

unit GetChart;

interface

uses
  System.Collections, System.ComponentModel,
  System.Data, System.Drawing, System.Web, System.Web.SessionState,
  System.Web.UI, System.Web.UI.WebControls, System.Web.UI.HtmlControls,
  System.IO;

type
  TWebForm2 = class(System.Web.UI.Page)
  {$REGION 'Designer Managed Code'}
  strict private
    procedure InitializeComponent;
  {$ENDREGION}
  strict private
    procedure Page_Load(sender: System.Object; e: System.EventArgs);
  strict protected
    procedure OnInit(e: EventArgs); override;
  private
    { Private Declarations }
  public
    { Public Declarations }
  end;

implementation

{$REGION 'Designer Managed Code'}
/// <summary>
/// Required method for Designer support -- do not modify
/// the contents of this method with the code editor.
/// </summary>
procedure TWebForm2.InitializeComponent;
begin    
  Include(Self.Load, Self.Page_Load);
end;
{$ENDREGION}

procedure TWebForm2.Page_Load(sender: System.Object; e: System.EventArgs);
var
  chartName: String;
  chartStream: MemoryStream;
begin
  chartName := Request.QueryString['Chart'];
  if (Session[chartName] <> nil) then
  begin
    chartStream := System.IO.MemoryStream.Create;
    chartStream := (System.IO.MemoryStream(Session[chartName]));
    Response.OutputStream.Write(chartStream.ToArray, 0, (Integer(chartStream.Length)));
    chartStream.Close;
    Session.Remove(chartName);
  end;
end;

procedure TWebForm2.OnInit(e: EventArgs);
begin
  //
  // Required for Designer support
  //
  InitializeComponent;
  inherited OnInit(e);
end;

end.
I'm also going to send you the full project to your forums avatar e-mail address.