Top/Bottom line in a chart

TeeChart VCL for Borland/CodeGear/Embarcadero RAD Studio, Delphi and C++ Builder.
Post Reply
EdDressel
Newbie
Newbie
Posts: 35
Joined: Mon Nov 25, 2019 12:00 am

Top/Bottom line in a chart

Post by EdDressel » Thu Apr 09, 2020 3:53 pm

I have a horizontal bar series in a chart. A customer wants the axis line on the bottom of the chart to extend farther left, and one at the top that matches. See here:

Image

I put arrows showing the lines.

Is something like this possible? (I have attached a demo--if it can be done, do you mind updating the demo).

Much appreciated.

Ed Dressel
Attachments
HorzSeriesExtentAxisLeft.zip
(6.77 KiB) Downloaded 798 times
Ed Dressel
President
RetireReady Solutions

Yeray
Site Admin
Site Admin
Posts: 9533
Joined: Tue Dec 05, 2006 12:00 am
Location: Girona, Catalonia
Contact:

Re: Top/Bottom line in a chart

Post by Yeray » Tue Apr 14, 2020 8:15 am

Hello,

Here with a margin of 10 pixels each side:
Project1_2020-04-14_10-14-09.png
Project1_2020-04-14_10-14-09.png (12.82 KiB) Viewed 13435 times
Attachments
HorzSeriesExtentAxisLeft.zip
(2.11 KiB) Downloaded 796 times
Best Regards,
ImageYeray Alonso
Development & Support
Steema Software
Av. Montilivi 33, 17003 Girona, Catalonia (SP)
Image Image Image Image Image Image Please read our Bug Fixing Policy

EdDressel
Newbie
Newbie
Posts: 35
Joined: Mon Nov 25, 2019 12:00 am

Re: Top/Bottom line in a chart

Post by EdDressel » Wed Apr 15, 2020 3:52 pm

Thank you. That works perfect for the TChart, but when I create an image of the chart with a different width, the lines are not the correct width. See the attached demo--the red lines are painted in the AfterDraw event and are not the correct width.
Attachments
HorzSeriesExtentAxisLeft.zip
(3.1 KiB) Downloaded 825 times
Ed Dressel
President
RetireReady Solutions

EdDressel
Newbie
Newbie
Posts: 35
Joined: Mon Nov 25, 2019 12:00 am

Re: Top/Bottom line in a chart

Post by EdDressel » Mon Apr 20, 2020 2:01 pm

Hello?
Ed Dressel
President
RetireReady Solutions

Marc
Site Admin
Site Admin
Posts: 1213
Joined: Thu Oct 16, 2003 4:00 am
Location: Girona
Contact:

Re: Top/Bottom line in a chart

Post by Marc » Wed Apr 22, 2020 5:49 pm

Hello,

This is an option:

Add two new variables in the var declarations of the Form:

Code: Select all

var
  Form1: TForm1;
  aWidth, chartWidth : Integer; ///<-- these
In FormCreate initialise the variables:

Code: Select all

procedure TForm1.FormCreate(Sender: TObject);
var
  I: Integer;
  lValue: Double;
begin
  aWidth:=Chart1.Width;  //<-- here
  chartWidth:=aWidth;  //<-- and here
  Series1.Clear;
In the AssignChartToGraphic method add in a set for aWidth:

Code: Select all

  lCanvasClass := TCanvas3DClass(aChart.Canvas.ClassType);
  if lCanvasClass <> TTeeCanvas3D then
    aChart.Canvas := TTeeCanvas3D.Create;

  aWidth:=aRect.Right;  //<--- here

  lHoldGradientVisible := aChart.Gradient.Visible;
In the OnAfterDraw event add in the variable width size and reset the variable.
ie.

Code: Select all

procedure TForm1.Chart1AfterDraw(Sender: TObject);
begin
  with Chart1.Canvas do begin
    Pen.Color := clRed;
    Pen.Width := Chart1.BottomAxis.Axis.Width;

    HorizLine3D(10,aWidth-10,Chart1.ChartRect.Top,0);
    HorizLine3D(10,aWidth-10,Chart1.Axes.Bottom.PosAxis+1,0);

    aWidth:=chartWidth; //reset
  end;
end;
Unit attached.
Unit1.zip
(1.59 KiB) Downloaded 797 times
Regards,
Marc
Steema Support

Post Reply