Resizing Chart - axis labels in wrong location

TeeChart VCL for Borland/CodeGear/Embarcadero RAD Studio, Delphi and C++ Builder.
msimmons
Newbie
Newbie
Posts: 15
Joined: Tue Oct 21, 2008 12:00 am

Resizing Chart - axis labels in wrong location

Post by msimmons » Wed Oct 29, 2008 7:48 pm

I've been looking at the "Chart CustomChartRect" example in the features demo and attempting to get my chart to behave correctly. I apparently am doing something wrong but haven't been able to spot the problem.

I can successfully resize the chart using the TRectangle resized event. But my axis labels are drawn in the incorrect locations:
1. The left axis is where it should be, but the labels are in the middle of the graph.
2. The left axis title is in the left wall instead of being left of the axis.
3. The bottom axis labels are inside the graph as well.

I've tried adjusting various properties but cannot get it to behave. Can you point me in the direction of a property to check?

Thanks
Mike Simmons


unit APMGR022;

interface

uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, Apmgrgl, Buttons, APMGRDAT, dxSkinsCore, dxSkinsDefaultPainters,
dxSkinsdxBarPainter, cxPropertiesStore, dxBar, cxClasses,
cxLookAndFeelPainters, TeeGalleryPanel, cxSplitter, StdCtrls, TeeLisB,
cxControls, cxContainer, cxEdit, cxGroupBox, TeeProcs, TeEngine, Chart,
ExtCtrls, TeeComma, TeeEdit, Teetools, TeeDataTableTool, Series,
TeeSelectorTool;

type
TGraphForm = class(TForm)
dxBarManager1: TdxBarManager;
dxBarManager1Bar1: TdxBar;
dxBarButton1: TdxBarButton;
cxPropertiesStore1: TcxPropertiesStore;
TeeCommander1: TTeeCommander;
Chart1: TChart;
cxGroupBox1: TcxGroupBox;
ChartListBox1: TChartListBox;
Splitter2: TcxSplitter;
ChartGalleryPanel1: TChartGalleryPanel;
Splitter1: TcxSplitter;
ChartEditor1: TChartEditor;
procedure dxBarButton1Click(Sender: TObject);
procedure FormCloseQuery(Sender: TObject; var CanClose: Boolean);
procedure FormClose(Sender: TObject; var Action: TCloseAction);
procedure FormShow(Sender: TObject);
procedure ChartGalleryPanel1ChangeChart(Sender: TObject);
procedure TeeCommander1SetLabel(Sender: TTeeCommander; var Text: string);
procedure SetChartVisibility;
procedure ToggleDataTable(Sender: TObject);
procedure ShowHideGallery(Sender: TObject);
procedure ShowHideSeries(Sender: TObject);
procedure TogglePercent(Sender: TObject);
procedure Setup(PPct, DataTable: Boolean);
procedure MakeBar(SeriesTitle: String; MultB: TMultiBar; SColor: TColor);
procedure MakeArea(SeriesTitle: String; Transp: Integer; SColor: TColor);
procedure LoadSeriesData(SeriesData: PtrChartSeriesTable; SeriesName: String );
procedure SetCaption(Title: String);
procedure ChartTool1Dragged(Sender: TObject);
procedure Chart1AfterDraw(Sender: TObject);
private
{ Private declarations }
MarkTips: TMarksTipTool;
DATA: TDataTableTool;
BarTemp: TBarSeries;
AreaTemp: TAreaSeries;
LastMultiBar: TMultiBar;
Rect1: TRectangleTool;
public
{ Public declarations }
end;

var
GraphForm: TGraphForm;

implementation

{$R *.dfm}


procedure TGraphForm.ChartGalleryPanel1ChangeChart(Sender: TObject);
var tmpSeries : TChartSeries;
begin
tmpSeries:=ChartGalleryPanel1.SelectedChart[0];
ChangeAllSeriesType(Chart1,TChartSeriesClass(tmpSeries.ClassType));
end;

procedure TGraphForm.dxBarButton1Click(Sender: TObject);
begin
Close;
end;

procedure TGraphForm.FormClose(Sender: TObject; var Action: TCloseAction);
begin
cxPropertiesStore1.StoreTo(False);
Action := caFree;
end;

procedure TGraphForm.FormCloseQuery(Sender: TObject; var CanClose: Boolean);
begin
Canclose := True;
end;

procedure TGraphForm.FormShow(Sender: TObject);
begin
cxPropertiesStore1.StorageName := 'SOFTWARE\ISD\' + G_SoftwareName + '\CurrentVersion\' + Self.Name;
cxPropertiesStore1.RestoreFrom;

end;

procedure TGraphForm.TeeCommander1SetLabel(Sender: TTeeCommander;
var Text: string);
begin
Text := '';
end;

procedure TGraphForm.Setup(PPct, DataTable: Boolean);
Var
RPos,i,j: Integer;
begin
// Adjust Title Line properties
Chart1.Title.Text.Clear;
Chart1.Color := clWhite;
Chart1.Title.Font.Color := clNavy;
Chart1.Title.Font.Size := 12;
Chart1.Foot.Font.Color := clNavy;
Chart1.Foot.Font.Size := 12;
Chart1.Pages.AutoScale := True;
Chart1.Legend.Visible := False; // Hide series legend
Chart1.OnClickSeries := nil;
// Create mouseover tip displayer and add to chart
MarkTips := TMarksTipTool.Create(self);
MarkTips.Style := smsValue;
MarkTips.MouseAction := mtmMove;
MarkTips.MouseDelay := 200;
MarkTips.Active := True;
Chart1.Tools.Add(MarkTips);
// Create DataTableTool and add to chart
DATA := TDataTableTool.Create(Self);
DATA.ParentChart := Chart1;
DATA.AutoPosition := True;
DATA.ClipText := True;
DATA.Active := DataTable;
Chart1.Tools.Add(DATA);
Rect1 := TRectangleTool.CReate(Self);
With Rect1 do
Begin
ParentChart := Chart1;
Active := False;
Callout.Brush.BackColor := clAqua;
Callout.Arrow.Visible := False;
Shape.Shadow.HorizSize := 0;
Shape.Shadow.VertSize := 0;
Shape.Transparency := 75;
Shape.AutoSize := False;
Shape.Cursor := crHandPoint;
OnDragged := ChartTool1Dragged;
OnResized := ChartTool1Dragged;
Visible := True;
End;
Chart1.Tools.Add(RECT1);
Rect1.Active := False;
//Chart1.CustomChartRect:=True;

// TSEL := TSelectorTool.Create(self);
// TSEL.AllowDrag := True;
// TSEL.ParentChart := Chart1;
// TSEL.AllowResizeChart := True;
// Chart1.Tools.Add(TSEL);

RPos := 0;
With TeeCommander1 do
Begin
For i := 0 to Pred(ControlCount) do
Begin
If Controls is TSpeedButton
Then j := (Controls as TSpeedButton).Boundsrect.Right
Else
If Controls is TLabel
Then j := (Controls as TLabel).Boundsrect.Right
Else j := 0;
If j > RPos
Then RPos := j;
End;
End;
With TeeCommander1.CreateButton(RPos + 4 ,ShowHideGallery,'Gallery','',103) do
Begin
DM1.TChartImageList.GetBitMap(3, Glyph);
NumGlyphs := 1;
RPos := RPos + 29;
End;
With TeeCommander1.CreateButton(RPos + 4,ToggleDataTable,'Data Table','',101) do
Begin
DM1.TChartImageList.GetBitMap(1, Glyph);
NumGlyphs := 1;
RPos := RPos + 29;
End;
With TeeCommander1.CreateButton(RPos + 4,ShowHideSeries,'Series List','',102) do
Begin
DM1.TChartImageList.GetBitMap(2, Glyph);
NumGlyphs := 1;
RPos := RPos + 29;
End;
If PPct
Then Begin
With TeeCommander1.CreateButton(RPos + 4,TogglePercent,'Percentage View','',100) do
Begin
DM1.TChartImageList.GetBitMap(0, Glyph);
NumGlyphs := 1;
End;
End;
With ChartGalleryPanel1 do
begin
NumCols:=1;
NumRows:=9;
CreateChartList([THorizBarSeries,TLineSeries,THorizLineSeries,
TBarSeries, TCircledSeries,
TAreaSeries,TPieSeries,THorizAreaSeries,
TPointSeries]);
end;

end;

procedure TGraphForm.SetChartVisibility;
begin
If (not ChartListBox1.Visible) and
(not ChartGalleryPanel1.Visible)
Then Begin
cxGroupBox1.Visible := False;
Splitter1.Visible := False;
Exit;
End;
Splitter1.Visible := True;
cxGroupBox1.Visible := True;
Splitter2.Visible := ChartListBox1.Visible and
ChartGalleryPanel1.Visible;
If ChartListBox1.Visible and
(not ChartGalleryPanel1.Visible)
Then ChartListBox1.Align := ALClient
Else Begin
If ChartListBox1.Align = ALClient
Then Begin
ChartListBox1.Align := ALTop;
ChartListBox1.Height := cxGroupBox1.Height div 4;
End;
End;
end;

procedure TGraphForm.TogglePercent(Sender: TObject);
Var
i: Integer;
begin
(Sender as TSpeedButton).AllowAllUp := True;
if Chart1.SeriesCount > 0 then
for i := 0 to Chart1.SeriesCount-1 do
if (Chart1.Series is TBarSeries) or
(Chart1.Series is THorizBarSeries)
then begin
With TCustomBarSeries(Chart1.Series) do
Begin
If MultiBar <> mbStacked100
Then Begin
LastMultiBar := MultiBar;
MultiBar := mbStacked100;
End
Else Begin
MultiBar := LastMultibar;
End;
(Sender as TSpeedButton).Down := MultiBar = mbStacked100;
End;
Exit; // only do for 1st bar found
end;
(Sender as TSpeedButton).Down := False;
end;

procedure TGraphForm.ShowHideSeries(Sender: TObject);
begin
ChartListBox1.Visible := not ChartListBox1.Visible;
(Sender as TSpeedButton).AllowAllUp := True;
(Sender as TSpeedButton).Down := ChartListBox1.Visible;
SetChartVisibility;
end;
procedure TGraphForm.ShowHideGallery(Sender: TObject);
begin
ChartGalleryPanel1.Visible := not ChartGalleryPanel1.Visible;
(Sender as TSpeedButton).AllowAllUp := True;
(Sender as TSpeedButton).Down := ChartGalleryPanel1.Visible;
SetChartVisibility;
end;

procedure TGraphForm.ToggleDataTable(Sender: TObject);
begin
Data.Active := not Data.Active;
(Sender as TSpeedButton).AllowAllUp := True;
(Sender as TSpeedButton).Down := Data.Active;
end;

procedure TGraphForm.MakeBar(SeriesTitle: String; MultB: TMultiBar; SColor: TColor);
begin
BarTemp := TBarSeries.Create(Self);
With BarTemp do
Begin
ParentChart := Chart1;
Title := SeriesTitle;
Marks.Style := smsValue;
Marks.Visible := False;
Color := SColor;
MultiBar := MultB;
End;
LastMultiBar := MultB;
end;

procedure TGraphForm.MakeArea(SeriesTitle: String; Transp: Integer; SColor: TColor);
begin
AreaTemp := TAreaSeries.Create(Self);
With AreaTemp do
Begin
ParentChart := Chart1;
Title := SeriesTitle;
Marks.Style := smsValue;
Marks.Visible := False;
Transparency := TRansp;
Color := SColor;
End;
end;

procedure TGraphForm.SetCaption(Title: String);
Begin
Caption := Title + ' (AM022)';
End;

procedure TGraphForm.ChartTool1Dragged(Sender: TObject);
begin
with Chart1 do
begin
ChartRect:=Rect1.Bounds;
Chart1.Axes.Left.LabelsSize:=-10;
Chart1.Axes.Bottom.LabelsSize:=-10;
Invalidate;
end;
end;

procedure TGraphForm.LoadSeriesData(SeriesData: PtrChartSeriesTable; SeriesName: String );
Var
i,j: Integer;
Col: TColor;
begin
With Chart1 do
Begin
For i := 0 to Pred(SeriesCount) do
Begin
If Series.Title = SeriesName
Then Begin
Series.Clear;
For j := Low(SeriesData^) to High(SeriesData^) do
Begin
Col := SeriesData^[j].Color;
If Col = -1
Then Col := clTeeColor;
Series.Add(SeriesData^[j].Value,
SeriesData^[j].PointName, Col);
If SeriesData^[j].Value = 0
Then Series[i].SetNull(j);
End;
End;
End;
End;
ChartListBox1.UpdateSeries;
end;

procedure TGraphForm.Chart1AfterDraw(Sender: TObject);
begin
If not Rect1.Active
Then Begin
Rect1.Left := Chart1.ChartRect.Left;
Rect1.Top := Chart1.ChartRect.Top;
Rect1.Height := Chart1.ChartHeight;
Rect1.Width := Chart1.ChartWidth;
Rect1.Active := True;
Chart1.Title.CustomPosition:=True;
Chart1.Legend.CustomPosition:=True;
Chart1.CustomChartRect:=True;
End;
end;

end.

object GraphForm: TGraphForm
Left = 0
Top = 0
Caption = 'GraphForm'
ClientHeight = 528
ClientWidth = 564
Color = clBtnFace
Font.Charset = DEFAULT_CHARSET
Font.Color = clWindowText
Font.Height = -11
Font.Name = 'Tahoma'
Font.Style = []
OldCreateOrder = False
OnClose = FormClose
OnCloseQuery = FormCloseQuery
OnShow = FormShow
PixelsPerInch = 96
TextHeight = 13
object TeeCommander1: TTeeCommander
Left = 0
Top = 26
Width = 564
Height = 33
Panel = Chart1
Align = alTop
ParentShowHint = False
TabOrder = 0
ChartEditor = ChartEditor1
OnSetLabel = TeeCommander1SetLabel
end
object Chart1: TChart
Left = 169
Top = 59
Width = 395
Height = 469
Foot.Text.Strings = (
'')
Title.Font.Height = -16
Title.Text.Strings = (
'TChart')
Pages.AutoScale = True
OnAfterDraw = Chart1AfterDraw
Align = alClient
Color = clWhite
TabOrder = 1
ColorPaletteIndex = 13
end
object cxGroupBox1: TcxGroupBox
Left = 0
Top = 59
Align = alLeft
Style.BorderStyle = ebsNone
TabOrder = 6
Visible = False
Height = 469
Width = 161
object ChartListBox1: TChartListBox
Left = 2
Top = 18
Width = 157
Height = 97
Chart = Chart1
Align = alTop
ItemHeight = 24
TabOrder = 0
Visible = False
end
object Splitter2: TcxSplitter
Left = 2
Top = 115
Width = 157
Height = 8
HotZoneClassName = 'TcxSimpleStyle'
AlignSplitter = salTop
Control = ChartListBox1
Visible = False
end
object ChartGalleryPanel1: TChartGalleryPanel
Left = 2
Top = 123
Width = 157
Height = 344
Smooth = True
OnChangeChart = ChartGalleryPanel1ChangeChart
Align = alClient
BevelOuter = bvNone
ParentColor = True
TabOrder = 2
Visible = False
end
end
object Splitter1: TcxSplitter
Left = 161
Top = 59
Width = 8
Height = 469
HotZoneClassName = 'TcxSimpleStyle'
Control = cxGroupBox1
end
object dxBarManager1: TdxBarManager
Font.Charset = DEFAULT_CHARSET
Font.Color = clWindowText
Font.Height = -11
Font.Name = 'Tahoma'
Font.Style = []
Categories.Strings = (
'Default')
Categories.ItemsVisibles = (
2)
Categories.Visibles = (
True)
PopupMenuLinks = <>
UseSystemFont = True
Left = 168
Top = 144
DockControlHeights = (
0
0
26
0)
object dxBarManager1Bar1: TdxBar
AllowClose = False
AllowCustomizing = False
AllowQuickCustomizing = False
Caption = 'Main Menu'
CaptionButtons = <>
DockedDockingStyle = dsTop
DockedLeft = 0
DockedTop = 0
DockingStyle = dsTop
FloatLeft = 590
FloatTop = 8
FloatClientWidth = 0
FloatClientHeight = 0
IsMainMenu = True
ItemLinks = <
item
Visible = True
ItemName = 'dxBarButton1'
end>
MultiLine = True
OneOnRow = True
Row = 0
UseOwnFont = False
Visible = True
WholeRow = True
end
object dxBarButton1: TdxBarButton
Caption = 'Close'
Category = 0
Hint = 'Close'
Visible = ivAlways
OnClick = dxBarButton1Click
end
end
object cxPropertiesStore1: TcxPropertiesStore
Active = False
Components = <
item
Component = Owner
Properties.Strings = (
'Left'
'Top')
end>
StorageName = 'cxPropertiesStore1'
StorageType = stRegistry
Left = 272
Top = 208
end
object ChartEditor1: TChartEditor
Chart = Chart1
TreeView = True
Left = 344
Top = 280
end
end

Narcís
Site Admin
Site Admin
Posts: 14730
Joined: Mon Jun 09, 2003 4:00 am
Location: Banyoles, Catalonia
Contact:

Post by Narcís » Thu Oct 30, 2008 10:10 am

Hi Mike,

Would you be so kind to post this example at the news://www.steema.net/steema.public.attachments newsgroup or at our upload page?

Thank you very much.
Best Regards,
Narcís Calvet / Development & Support
Steema Software
Avinguda Montilivi 33, 17003 Girona, Catalonia
Tel: 34 972 218 797
http://www.steema.com
Image Image Image Image Image Image
Instructions - How to post in this forum

msimmons
Newbie
Newbie
Posts: 15
Joined: Tue Oct 21, 2008 12:00 am

Posted at Newsgroup

Post by msimmons » Thu Oct 30, 2008 2:25 pm

Hi Narcis,

I have posted the topic where you directed. A simplified project is attached.

Regards,
Mike Simmons

Narcís
Site Admin
Site Admin
Posts: 14730
Joined: Mon Jun 09, 2003 4:00 am
Location: Banyoles, Catalonia
Contact:

Post by Narcís » Thu Oct 30, 2008 3:08 pm

Hi Mike,

Thanks for the example project. Commenting the Chart1.CustomChartRect:=True line makes the chart resize correctly. What are you exactly trying to achieve with CustomChartRect?

Thanks in advance.
Best Regards,
Narcís Calvet / Development & Support
Steema Software
Avinguda Montilivi 33, 17003 Girona, Catalonia
Tel: 34 972 218 797
http://www.steema.com
Image Image Image Image Image Image
Instructions - How to post in this forum

msimmons
Newbie
Newbie
Posts: 15
Joined: Tue Oct 21, 2008 12:00 am

Resizing Chart - axis labels in wrong location

Post by msimmons » Thu Oct 30, 2008 3:26 pm

Hi Narcis,

I recently switched from using the ChartFX 5.1 Server component to TeeChart Pro. One of the features that my users are used to having is an easy way to resize the plot area so that (as one example) the graph size could be vertically reduced to provide more space for vertical labels along the x-axis.

So that's what I'm trying to do. I realize changing the customchartrect to false fixes the problem, but then I cannot resize the plot area.

I originally tried using a TSelector tool. That allows me to resize the TChart, but not resize the plot area on the TChart canvas.

Thanks,
Mike Simmons

Pep
Site Admin
Site Admin
Posts: 3295
Joined: Fri Nov 14, 2003 5:00 am
Contact:

Post by Pep » Mon Nov 03, 2008 12:03 pm

Hello Mike,

an easy way would be to use the CustomChartRect property and allow to resize the ChartRect area by cliking over the bottom axis ( in ths case ) and dragging :

Code: Select all

procedure TForm1.Chart1MouseMove(Sender: TObject; Shift: TShiftState; X,
  Y: Integer);
begin
 if (mousedown) and (chart1.Axes.Bottom.Clicked(x,y)) then
 begin
   Chart1.CustomChartRect := true;
   Chart1.ChartRect.Bottom := y;

   Chart1.Axes.Left.LabelsSize:=-10;
   Chart1.Axes.Bottom.LabelsSize:=-10;

   Chart1.Repaint;
 end;
end;

msimmons
Newbie
Newbie
Posts: 15
Joined: Tue Oct 21, 2008 12:00 am

Resizing Chart - axis labels in wrong location

Post by msimmons » Mon Nov 03, 2008 2:40 pm

Hi Josep,

Thank you for the mousemove example for resing the chart. That is MUCH easier to implement that the TRectangle method.

However, I'm still experiencing labels and titles printing in the incorrect place after resizing. I placed a new topic into the steema.public.attachments forum along with a ZIP file. The zip file contains a revised sample project and a JPG file that show before and after images.

Thanks,
Mike Simmons

Narcís
Site Admin
Site Admin
Posts: 14730
Joined: Mon Jun 09, 2003 4:00 am
Location: Banyoles, Catalonia
Contact:

Post by Narcís » Tue Nov 04, 2008 8:23 am

Hi Mike,

Thanks for the example project but I'm not able to reprdouce what's shown in your images with it. Should I follow any specific step to reproduce it?

Thanks in advance.
Best Regards,
Narcís Calvet / Development & Support
Steema Software
Avinguda Montilivi 33, 17003 Girona, Catalonia
Tel: 34 972 218 797
http://www.steema.com
Image Image Image Image Image Image
Instructions - How to post in this forum

msimmons
Newbie
Newbie
Posts: 15
Joined: Tue Oct 21, 2008 12:00 am

Resizing Chart - axis labels in wrong location

Post by msimmons » Tue Nov 04, 2008 12:04 pm

Hi Narcis,

1. Run the application
2. Click the far right button on the TCommander to show the datatable.
3. Click and drag the bottom axis downward (or upward) to resize the plot area vertically.

Rgards,
Mike Simmons

Narcís
Site Admin
Site Admin
Posts: 14730
Joined: Mon Jun 09, 2003 4:00 am
Location: Banyoles, Catalonia
Contact:

Post by Narcís » Tue Nov 04, 2008 12:12 pm

Hi Mike,

Thanks for the information but this works fine for me here using TeeChart Pro v8.04 VCL. Which is the TeeChart version you are using?

Thanks in advance.
Best Regards,
Narcís Calvet / Development & Support
Steema Software
Avinguda Montilivi 33, 17003 Girona, Catalonia
Tel: 34 972 218 797
http://www.steema.com
Image Image Image Image Image Image
Instructions - How to post in this forum

msimmons
Newbie
Newbie
Posts: 15
Joined: Tue Oct 21, 2008 12:00 am

Resizing Chart - axis labels in wrong location

Post by msimmons » Tue Nov 04, 2008 12:33 pm

Hi Narcis,

How odd that it behaves for you. I will upload a zipped version of the executable as compiled on my end.

When I right click on TChart component, it shows v8.04.11395.

I am running Delphi 2007 on Windows XP SP 3

Regards,
Mike Simmons

msimmons
Newbie
Newbie
Posts: 15
Joined: Tue Oct 21, 2008 12:00 am

Post by msimmons » Tue Nov 04, 2008 3:56 pm

Hi Narcis,

The zipped excutable was to large to upload to the attachments newsgroup.

I've placed it at:
http://members.isd-inc.com/files/Resize ... xeOnly.zip

Regards,
Mike Simmons

msimmons
Newbie
Newbie
Posts: 15
Joined: Tue Oct 21, 2008 12:00 am

Post by msimmons » Wed Nov 05, 2008 4:27 pm

Hi Narcis,

Were you able to see the problem with the compiled executable?

I have rerun the Install tool. The problem is still persisting. Have you any idea what I can try to check? I have developers express components as well.

Thanks,
Mike Simmons

Narcís
Site Admin
Site Admin
Posts: 14730
Joined: Mon Jun 09, 2003 4:00 am
Location: Banyoles, Catalonia
Contact:

Post by Narcís » Thu Nov 06, 2008 8:16 am

Hi Mike,

Yes, I was able to reproduce the issue here using your project too. We are investing it here and will get back to you when we have further news.
Best Regards,
Narcís Calvet / Development & Support
Steema Software
Avinguda Montilivi 33, 17003 Girona, Catalonia
Tel: 34 972 218 797
http://www.steema.com
Image Image Image Image Image Image
Instructions - How to post in this forum

msimmons
Newbie
Newbie
Posts: 15
Joined: Tue Oct 21, 2008 12:00 am

Post by msimmons » Mon Nov 17, 2008 6:57 pm

Hi Narcis,

I have not heard anything back on this yet. Do you have any idea when a fix or workaround might be available?

Best Regards,
Mike Simmons

Post Reply