Page 1 of 1

Top/Bottom line in a chart

Posted: Thu Apr 09, 2020 3:53 pm
by 16587426
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

Re: Top/Bottom line in a chart

Posted: Tue Apr 14, 2020 8:15 am
by yeray
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 13413 times

Re: Top/Bottom line in a chart

Posted: Wed Apr 15, 2020 3:52 pm
by 16587426
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.

Re: Top/Bottom line in a chart

Posted: Mon Apr 20, 2020 2:01 pm
by 16587426
Hello?

Re: Top/Bottom line in a chart

Posted: Wed Apr 22, 2020 5:49 pm
by Marc
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 794 times
Regards,
Marc