X Axis point offset

Good afternoon to all,

j'm new with this component and before repleace my teechart work, j'm trying to create e new form with new chart.



I have a little problem with pane X axsis value offset while use number and the chart is setted to show a bars in only one serie.

In the component the x axis have 0,1,2,...n and j chenge the number with a string via

.Panes[0].Series[0].AddSinglePoint(MyCurrencyValue,MyString);



Now in order to avoid collision with the string j need to increase the "point" offset in this way

(Component default x axis offset)

0 1 2 3 4

Result to obtain

0   1   2   3   4



My first priority is the problem above, but it's is also desirable get this kind of result, always, on x axis something like this (odd value have the string up and even have the string x pixel bottom)

0        2        4

      1        3



j tried with

DrawXAxisValue(Sender: TObject; Serie: TChartSerie; Canvas: TCanvas;

                                 ARect: TRect; ValueIndex: Integer; XMarker: Integer;

                                 Top: Boolean; var defaultdraw: Boolean);

without a result

      

There's a way to get this ???



Thank's in advance for your reply



Best regard



Daniele







Hi, 


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. The top spacing between the X-Axis values cannot be changed, unless you want to draw using the OnXAxisDrawValue event. 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;

Kind Regards, 
Pieter

Hi Pieter,

thank's for your reply and thank's for your code in order to draw, on X axis, the text in that way.



I solve the distance between the bar, as you suggest, via RangeTo; i change the dimension of the form/frame in accordance with my need, now j have the correct number of the bar (4-5) and the correct space.



Now j have some new trouble, but are topics posted in another message.



Thank's again for your support



Regards



Daniele