Frequently Asked Component Specific Questions

Options

Display all FAQ items

Search FAQ items:


Displaying items 1 to 1 of 1, page 1 of 1

<< previous next >>

TMS VCL Chart
Custom x-axis value drawing

The distance between X-Axis values is determined by the X-Scale, which is calculated based on the RangeFrom and RangeTo properties on pane level. Additionally, the X-Axis can display major units and minor units with their own font size. Below is a sample that demonstrates this:

procedure TForm127.DrawXAxisValue(Sender: TObject; Serie: TChartSerie; Canvas: TCanvas; ARect: TRect; ValueIndex, XMarker: integer; Top: Boolean; var defaultdraw: Boolean);
var
  s: string;
  tw: Integer;
begin
  if Odd(ValueIndex) then
  begin
    DefaultDraw := False;
    s := IntToStr(ValueIndex);
    tw := Canvas.TextWidth(s);
    Canvas.Pen.Color := clRed;
    Canvas.MoveTo(XMarker, ARect.Top);
    Canvas.LineTo(XMarker, ARect.Top + 15);
    Canvas.Font.Color := clRed;
    Canvas.TextOut(XMarker - tw div 2, ARect.Top + 17, s);
  end;
end;

procedure TForm127.FormCreate(Sender: TObject);
var
  I: Integer;
begin
  AdvGDIPChartView1.BeginUpdate;
  AdvGDIPChartView1.InitSample;
  AdvGDIPChartView1.Panes[0].Range.RangeTo := 15;
  AdvGDIPChartView1.Panes[0].XAxis.AutoSize := True;
  AdvGDIPChartView1.Panes[0].Series[2].Free;
  AdvGDIPChartView1.Panes[0].Series[1].Free;
  AdvGDIPChartView1.Panes[0].Series[0].ClearPoints;
  AdvGDIPChartView1.Panes[0].Series[0].AutoRange := arEnabled;
  AdvGDIPChartView1.Panes[0].Series[0].XAxis.AutoUnits := False;
  AdvGDIPChartView1.Panes[0].Series[0].XAxis.MajorUnit := 2;
  AdvGDIPChartView1.Panes[0].Series[0].XAxis.MinorUnit := 1;
  AdvGDIPChartView1.Panes[0].Series[0].OnXAxisDrawValue := DrawXAxisValue;

  for I := 0 to 14 do
    AdvGDIPChartView1.Panes[0].Series[0].AddSinglePoint(Random(100));

  AdvGDIPChartView1.EndUpdate;
end;