Page 1 of 1

Values / labels within a period, not at a certain mark

Posted: Wed Nov 23, 2011 9:55 am
by 10555564
Hello,

I have some basic experience with TeeChart, but it seems to be not enough for my current need, so I would like to ask for help.

I would like to create a Chart (Line or Points), which shows daily price changes for a period of a year. But the bottom axis shouldn't show those 365 days, but 12 periods for each month - something like this.

For this I'm creating 365 records in my dataset, which has a field "DAY" with the appropriate day number. It also has the fields "MONTH" and "MONTH_NUMBER". For this two fields first 31 records have the values "1" and "Jan", next 28 (29) have the values "2" and "Feb" and so on. But somehow I can't get the chart to display it like I want.

What I get is:
Image

What I would like to get is:
Image

Two major differences here:
- months are "just" labels of the 12 periods
- price changes are displayed not per month, but per day within a month (see 2 changes in October)

Is something like this possible? If so: how do I accomplish that?

Kind regards,
Alex

Re: Values / labels within a period, not at a certain mark

Posted: Wed Nov 23, 2011 4:31 pm
by 10050769
Hello Alex,

I recommend you use to add DateTimes Encode() method that allow you add a compost date adding the e year/month/day you want, you can find examples how use it in Tutorial number 4 Axis Control and number 6 Working with Series. Moreover I recommend you take a look in this example of DataSet where explain, how you do to make a DataSet in runtime and help you to create it, but you need translate it to VCL code, so this example is in TeeChart.net. If you have any problems please let me know.

I hope will helps.

Thanks,

Re: Values / labels within a period, not at a certain mark

Posted: Tue Nov 29, 2011 4:55 pm
by 10555564
Hello Sandra,

thank you for your reply!

I'm getting there slowly, I think.

So far I've managed to accomplish this:
Image

Compared to the first screenshot from the first post the marks are within a period now, which is correct.
But I still couldn't manage to accomplish this:
Image

I've tried to work with BottomAxis.MinimumOffset and BottomAxis.MaximumOffset + BottomAxis.GridCentered := true
The result looks ok in the first moment:
Image

But you can see that the values remain unaffected by these changes and while they are still correctly between the months, the grid lines look irritating... so that the first change, for instance, appears to be in september instead of august etc.

Any way to get this done correctly? All it would need is an offset for axis labels only...

Regards,
Alex

Re: Values / labels within a period, not at a certain mark

Posted: Fri Dec 02, 2011 2:01 pm
by yeray
Hi Alex,

I'm afraid you can't add an offset to the axis labels. We will consider including both an horizontal and vertical offset in a future version (TV52015940).
In the meanwhile, you can simply add some blank spaces ' ' at the beginning of your month strings. Depending on how are you exactly showing the labels, it should be done in the OnGetAxisLabel if you are using the default labels or just modifying the ShortMonthNames array.
I've checked it with the following code and it seems to work fine for me here:

Code: Select all

uses Series;

procedure TForm1.FormCreate(Sender: TObject);
var i: Integer;
    tmpDate: TDateTime;
const space='         ';
begin
  Chart1.View3D:=false;
  Chart1.Legend.Visible:=false;
  Chart1.Title.Visible:=false;

  with Chart1.AddSeries(TPointSeries) as TPointSeries do
  begin
    Pointer.Style:=psDiamond;
    Pointer.HorizSize:=5;
    Pointer.VertSize:=5;
    Pointer.Gradient.Visible:=true;
    Color:=clYellow;

    XValues.DateTime:=true;

    AddXY(StrToDateTime('17/08/2011'), 100);
    AddXY(StrToDateTime('17/10/2011'), 110);
    AddXY(StrToDateTime('17/11/2011'), 205);
    AddXY(StrToDateTime('20/11/2011'), 205);
    AddXY(StrToDateTime('22/11/2011'), 180);
  end;

  Chart1.Axes.Left.AutomaticMinimum:=false;
  Chart1.Axes.Left.Minimum:=0;
  Chart1.Axes.Bottom.SetMinMax(StrToDateTime('01/01/2011'), StrToDateTime('01/01/2012'));
  Chart1.Axes.Bottom.DateTimeFormat:='mmm';
  Chart1.Axes.Bottom.MinorTicks.Visible:=false;

  ShortMonthNames[1]:='Jan';
  ShortMonthNames[2]:='Feb';
  ShortMonthNames[3]:='Mrz';
  ShortMonthNames[4]:='Apr';
  ShortMonthNames[5]:='Mai';
  ShortMonthNames[6]:='Jun';
  ShortMonthNames[7]:='Jul';
  ShortMonthNames[8]:='Aug';
  ShortMonthNames[9]:='Sep';
  ShortMonthNames[10]:='Okt';
  ShortMonthNames[11]:='Nov';
  ShortMonthNames[12]:='Dez';

  Chart1.Axes.Bottom.Items.Clear;
  tmpDate:=Chart1.Axes.Bottom.Minimum;
  for i:=Low(ShortMonthNames) to High(ShortMonthNames) do
  begin
    Chart1.Axes.Bottom.Items.Add(tmpDate, space + ShortMonthNames[i]);
    tmpDate:=IncMonth(tmpDate);
  end;
end;
AxisLabels.png
AxisLabels.png (5.13 KiB) Viewed 4719 times

Re: Values / labels within a period, not at a certain mark

Posted: Mon Dec 05, 2011 3:51 pm
by 10555564
Hi Yeray,

it didn't work in the OnGetAxisLabel event, but then I've used this part of your code

Code: Select all

  Chart1.Axes.Bottom.Items.Clear;
  tmpDate:=Chart1.Axes.Bottom.Minimum;
  for i:=Low(ShortMonthNames) to High(ShortMonthNames) do
  begin
    Chart1.Axes.Bottom.Items.Add(tmpDate, space + ShortMonthNames[i]);
    tmpDate:=IncMonth(tmpDate);
  end;
after my chart was generated and it did work just fine.

Thanks a lot for your help and also for considering the addion of label offsets as a new feature!

Kind regards,
Alex

Re: Values / labels within a period, not at a certain mark

Posted: Mon Dec 05, 2011 4:01 pm
by narcis
Hi Alex,

Thanks for your feedback. I have added your request (TV52015943) to the wish-list to be considered for inclusion in future releases.