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 drawing

procedure TForm1.FormCreate(Sender: TObject);
var
  I: Integer;
begin
  AdvChartView1.BeginUpdate;
  AdvChartView1.Panes[0].Series[2].Free;
  AdvChartView1.Panes[0].Series[1].Free;
  AdvChartView1.Panes[0].Series[0].OnXAxisDrawValue := XAxisDrawVal; 
  AdvChartView1.Panes[0].Series[0].ChartType := ctBar; 
  AdvChartView1.Panes[0].Series[0].XAxis.AutoUnits := False;
  AdvChartView1.Panes[0].XAxis.AutoSize := False;
  AdvChartView1.Panes[0].Series[0].AutoRange := arEnabledZeroBased;
  AdvChartView1.Panes[0].XAxis.Size := 50;
  for I := 0 to 9 do
    AdvChartView1.Panes[0].Series[0].AddSinglePoint(Random(100), ''Item '' + inttostr(I));
  AdvChartView1.EndUpdate;
end;

procedure TForm1.XAxisDrawVal(Sender: TObject; Serie: TChartSerie;
  Canvas: TCanvas; ARect: TRect; ValueIndex, XMarker: integer; Top: Boolean;
  var defaultdraw: Boolean);
var
  bw, tw: Integer;
  s: string;
begin
  defaultdraw := False;
  bw := Serie.GetBarWidth(1) div 2;
  Canvas.Pen.Color := clBlack;
  Canvas.Pen.Width := 2;
  Canvas.MoveTo(XMarker - bw + 1 , ARect.Top);
  Canvas.LineTo(XMarker - bw + 1, ARect.Top + 10);
  Canvas.MoveTo(XMarker + bw + 1, ARect.Top);
  Canvas.LineTo(XMarker + bw + 1, ARect.Top + 10);
  s := Serie.Points[ValueIndex].LegendValue;
  tw := Canvas.TextWidth(s);
  Canvas.TextOut(XMarker - tw div 2, ARect.Top + 12, s);
end;