Page 1 of 1

Bottom axis resetting

Posted: Tue Sep 20, 2011 2:06 pm
by 16457861
I have a simple DBChart attached to a crosstab showing values by calendar month (labelled as 1-12 on the bottom axis). My chart has several series on it (automatically drawn from the data as it is grouped by calendar year.) This all displays correctly. If I smooth all of the series and hide all of the original series by setting visible to False, (so that only the smoothed series show) then my bottom axis re-labelles itself from 0-11. Why is this and how do I stop this from happening?
Simon

Re: Bottom axis resetting

Posted: Tue Sep 20, 2011 2:13 pm
by narcis
Hi Simon,

This is probably because your smoothed series are not set to DateTime values. You should probably do someting like the code below for all your series:

Code: Select all

  Chart1[0].XValues.DateTime:=True;
And also set bottom axis DateTimeFormat if necessary:

Code: Select all

  Chart1.Axes.Bottom.DateTimeFormat:='dd/MM/yyyy';
If problem persists please attach a simple example project we can run "as-is" to reproduce the problem here.

Thanks in advance.

Re: Bottom axis resetting

Posted: Tue Sep 20, 2011 3:15 pm
by 16457861
Hmm, I don't want the date shown on the bottom axis. I just want the month - I have this integer value in the table and I want to group by year (I have this integer value in the table too) so that I get one series for each year appearing on my chart. Are you saying that I can't smooth a crosstab chart unless I have a dateTime field on the bottom axis?

Simon

Re: Bottom axis resetting

Posted: Tue Sep 20, 2011 3:30 pm
by narcis
Hi Simon,

Sorry, my fault, I got it wrong. In that case the easiest thing you could do would be using the OnGetAxisLabel event manually parsing the labels, for example:

Code: Select all

procedure TForm1.Chart1GetAxisLabel(Sender: TChartAxis;
  Series: TChartSeries; ValueIndex: Integer; var LabelText: String);
var tmp: Double;
begin
  if Sender = Chart1.Axes.Bottom then
  begin
    tmp:=StrToFloat(LabelText) + 1;
    LabelText:=FloatToStr(tmp);
  end;
end;

Re: Bottom axis resetting

Posted: Wed Sep 21, 2011 7:35 am
by 16457861
Thanks Narcis, I can get it to work doing what you suggest, but of course the axis is then wrong for a non-smoothed series! I can get around this but it all seems like a bit of a bodge. Is this behaviour likely to be fixed at sometime?
Simon

Re: Bottom axis resetting

Posted: Wed Sep 21, 2011 8:46 am
by narcis
Hi Simon,

An alternative could be using TLineSeries.Smoothed property, for example:

Code: Select all

uses Series;

procedure TForm1.FormCreate(Sender: TObject);
var Series1: TLineSeries;
    i: Integer;
begin
  Series1:=TLineSeries.Create(Self);
  Chart1.AddSeries(Series1);

  for i:=1 to 12 do
    Series1.AddXY(i, random);

  Series1.Smoothed:=True;
end;
Anyway, using a line series with an associated smoothing function doesn't change bottom axis labels either. In the code snippet Series1 is a line series and Series2 is the line series of a smoothing function with Series1 as a datasource. Could you please attach a simple example project we can run "as-is" to reproduce the problem here?

Code: Select all

procedure TForm1.FormCreate(Sender: TObject);
var i: Integer;
begin
  for i:=1 to 12 do
    Series1.AddXY(i, random);

  Series2.CheckDataSource;
  Series1.Visible:=False;
end;
Thanks in advance.