Search code examples
delphiteechart

TChart with TKnobGauge creates shifted labels at runtime


Following code creates knob with labels shifted to the right:

procedure TForm1.FormShow(Sender: TObject);
begin
  _chart := TChart.Create(Self);
  _chart.Parent := Self;
  _chart.Align := alClient;

  _knob := TKnobGauge.Create(Self);
  _knob.ParentChart := _chart;
  _knob.RotateLabels := False;
  _knob.RotationAngle := 180;
end;

shifted knob labels

The same code as DFM produces the right knob.

What could be wrong?

  • TeeChart Pro v2015.16.150901 32bit VCL
  • Delphi 10

Solution

  • There is a bug in TChart. When I set

    _chart.Title.Text.Text := 'Some title';
    

    labels are on their places.

    When I do

    _chart.Title.Text.Text := '';
    

    or

    _chart.Title.Visible := False;
    

    they are shifted.

    The reason why the same code in DFM produced the right knob is that the visual designer extends my minimal chart declaration by adding several properties automatically. Among these properties was a chart title too. It is automatically filled by "TChart" text.