Label Ranges for Vertical Gauge Chart

TeeChart VCL for Borland/CodeGear/Embarcadero RAD Studio, Delphi and C++ Builder.
Post Reply
fodder
Newbie
Newbie
Posts: 1
Joined: Wed Feb 24, 2016 12:00 am

Label Ranges for Vertical Gauge Chart

Post by fodder » Fri Mar 18, 2016 1:33 am

Hi,

Can I label the ranges for vertical gauges charts with text? Can I have the ranges as arrows (similar to the Max Indicator) with labels to the left or right? Can I have ranges on the left side of the gauge as well as the right?

Thanks ALL

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

Re: Label Ranges for Vertical Gauge Chart

Post by Yeray » Fri Mar 18, 2016 11:37 am

Hello,

You can use OnAfterDraw event to draw labels or shapes where you want. Here it is an example drawing labels at the right side:

Code: Select all

uses TeeLinearGauge;

type TLinearGaugeAcess=class(TLinearGauge)
end;

var verticalGauge1: TLinearGauge;

procedure TForm1.FormCreate(Sender: TObject);
begin
  verticalGauge1:=Chart1.AddSeries(TLinearGauge) as TLinearGauge;
  verticalGauge1.Horizontal:=false;
end;

procedure TForm1.Chart1AfterDraw(Sender: TObject);

  function CalcPos(Value: Double): Integer;
  var tmp : TAxisValue;
      tmpAxisSize: Integer;
  begin
    tmpAxisSize:=TLinearGaugeAcess(verticalGauge1).IAxisRect.Bottom-TLinearGaugeAcess(verticalGauge1).IAxisRect.Top;
    tmp:=(Value-verticalGauge1.Minimum)*(tmpAxisSize/TLinearGaugeAcess(verticalGauge1).IRange);

    if verticalGauge1.Axis.Inverted then
      result:=TLinearGaugeAcess(verticalGauge1).IAxisRect.Top+Round(tmp)
    else
      result:=TLinearGaugeAcess(verticalGauge1).IAxisRect.Bottom-Round(tmp);
  end;

var i, XPos, YPos, tmpTextHeight: Integer;
    tmpValue: Double;
begin
  tmpTextHeight:=Chart1.Canvas.TextHeight('Wq');
  XPos:=TLinearGaugeAcess(verticalGauge1).IAxisRect.Right;

  for i:=0 to verticalGauge1.Ranges.Count-1 do
  begin
    tmpValue:=verticalGauge1.Ranges[i].StartValue;
    YPos:=CalcPos(tmpValue) - (tmpTextHeight div 2);
    Chart1.Canvas.TextOut(XPos+verticalGauge1.Ranges[i].Format.Size+5, YPos, FormatFloat('#,##0.##', tmpValue));

    tmpValue:=verticalGauge1.Ranges[i].EndValue;
    YPos:=CalcPos(tmpValue) - (tmpTextHeight div 2);
    Chart1.Canvas.TextOut(XPos+verticalGauge1.Ranges[i].Format.Size+5, YPos, FormatFloat('#,##0.##', tmpValue));
  end;
end;
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

Post Reply