Page 1 of 1

Label Ranges for Vertical Gauge Chart

Posted: Fri Mar 18, 2016 1:33 am
by 16577739
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

Re: Label Ranges for Vertical Gauge Chart

Posted: Fri Mar 18, 2016 11:37 am
by yeray
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;