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

TeeChart VCL for Borland/CodeGear/Embarcadero RAD Studio, Delphi and C++ Builder.
Post Reply
AlexD
Newbie
Newbie
Posts: 3
Joined: Thu Apr 01, 2010 12:00 am

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

Post by AlexD » Wed Nov 23, 2011 9:55 am

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

Sandra
Site Admin
Site Admin
Posts: 3132
Joined: Fri Nov 07, 2008 12:00 am

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

Post by Sandra » Wed Nov 23, 2011 4:31 pm

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,
Best Regards,
Sandra Pazos / Development & Support
Steema Software
Avinguda Montilivi 33, 17003 Girona, Catalonia
Tel: 34 972 218 797
http://www.steema.com
Image Image Image Image Image Image
Instructions - How to post in this forum

AlexD
Newbie
Newbie
Posts: 3
Joined: Thu Apr 01, 2010 12:00 am

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

Post by AlexD » Tue Nov 29, 2011 4:55 pm

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

Yeray
Site Admin
Site Admin
Posts: 9612
Joined: Tue Dec 05, 2006 12:00 am
Location: Girona, Catalonia
Contact:

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

Post by Yeray » Fri Dec 02, 2011 2:01 pm

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 4773 times
Best Regards,
ImageYeray Alonso
Development & Support
Steema Software
Av. Montilivi 33, 17003 Girona, Catalonia (SP)
Image Image Image Image Image Image Please read our Bug Fixing Policy

AlexD
Newbie
Newbie
Posts: 3
Joined: Thu Apr 01, 2010 12:00 am

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

Post by AlexD » Mon Dec 05, 2011 3:51 pm

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

Narcís
Site Admin
Site Admin
Posts: 14730
Joined: Mon Jun 09, 2003 4:00 am
Location: Banyoles, Catalonia
Contact:

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

Post by Narcís » Mon Dec 05, 2011 4:01 pm

Hi Alex,

Thanks for your feedback. I have added your request (TV52015943) to the wish-list to be considered for inclusion in future releases.
Best Regards,
Narcís Calvet / Development & Support
Steema Software
Avinguda Montilivi 33, 17003 Girona, Catalonia
Tel: 34 972 218 797
http://www.steema.com
Image Image Image Image Image Image
Instructions - How to post in this forum

Post Reply