TAChart Bottom axis marks issue lazarus / 31-LCL ---------------------------------------------------------------------- Чебурашка · 2021-12-22 08:09 Hello, I have a program that shows a bar series representing values on Y and days on X. I am using on X the recommended TDateTimeIntervalChartSource. Configuration of TDateTimeIntervalChartSource object: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i   // frament taken from .lfm   object DateTimeIntervalChartSource: TDateTimeIntervalChartSource    Params.MaxLength = 1    Params.MinLength = 1    Params.Options = [aipUseCount, aipUseMinLength, aipUseNiceSteps]    Params.Tolerance = 1    Steps = [dtsDay]    SuppressPrevUnit = False  end  The call that updates the contents is: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i     // int value corresponding to start day - 1     Chart.BottomAxis.Range.Min := fLastStartTime - 1; Chart.BottomAxis.Range.UseMin := True;     // int value corresponding to start day + 1    Chart.BottomAxis.Range.Max := fLastEndTime + 1; Chart.BottomAxis.Range.UseMax := True;     // Adjust Count in order to match when day ranges are longer (not clear why but seems to work fine both with Week view, month view and also longer intervals)    DateTimeIntervalChartSource.Params.Count :=    Math.Min(      System.Trunc(2.0 + System.Trunc((Chart.BottomAxis.Range.Max - Chart.BottomAxis.Range.Min) / 2.0) * 2.0 - 1)      , 41);     UserDefinedChartSourceActualWeights.BeginUpdate();    UserDefinedChartSourceActualWeights.Reset();    UserDefinedChartSourceActualWeights.PointsNumber := fHistory.Count - 1;    UserDefinedChartSourceActualWeights.EndUpdate();  Please see the following screenshots: All except Capture-Month-Zoom-12-24 (=query over one month but zoomed on day 12 to 24) show the bottom axis well. While I would like the bottom axis to be always visible regardless of the zoom level. Any clue? FULL SOURCE AND LFM Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i unit UFrameCyclesDailyWeightsHistory; {$mode objfpc}{$H+} interface uses  Classes, SysUtils, Forms, Controls, ExtCtrls, TAGraph, TASeries, TASources, TACustomSource, TAIntervalSources, TATransformations,  TATools, TAChartAxisUtils; type   { TFrameCyclesDailyWeightsHistory }   TFrameCyclesDailyWeightsHistory = class(TFrame)    Chart: TChart;    ChartAxisWeightTransformationsLeft: TChartAxisTransformations;    ChartAxisWeightTransformationsLeftAutoScaleAxisTransform: TAutoScaleAxisTransform;     ChartBarSeriesWeights: TBarSeries;    DateTimeIntervalChartSource: TDateTimeIntervalChartSource;    PanelChartControls: TPanel;    PanelMain: TPanel;    UserDefinedChartSourceActualWeights: TUserDefinedChartSource;    procedure ChartAxisList1MarkToText(var AText: String; AMark: Double);    procedure UserDefinedChartSourceGetChartDataItem(ASource: TUserDefinedChartSource; AIndex: Integer; var AItem: TChartDataItem);  private    fLastStartTime, fLastEndTime: TDateTime;    fHistory: TList;    fAverage: Pointer;  public    procedure SetSource(lastStartTime: TDateTime; lastEndTime: TDateTime; history: TList; average: Pointer);    procedure Translate();    procedure ShowContent();    constructor Create(TheOwner: TComponent); override;  end; implementation {$R *.lfm} uses  Graphics  , DateUtils  , Math   ,ProdLogQueries  ; /////////////////////////////////////////////////// /////////////////////////////// TFrameCyclesDailyWeightsHistory/////// ////////////////////////////////////////////////////////////////////// /// constructor TFrameCyclesDailyWeightsHistory.Create(TheOwner: TComponent);begin  inherited Create(TheOwner);   fHistory := nil;  fAverage := nil;end; procedure TFrameCyclesDailyWeightsHistory.UserDef inedChartSourceGetChartDataItem(ASource: TUserDefinedChartSource; AIndex: Integer;  var AItem: TChartDataItem);var  weightT: Single;begin  if (fHistory <> nil)     and (fHistory.Count > 1)     and (0 <= AIndex)     and (AIndex < fHistory.Count - 1)     then  begin    AItem.X :=  PPoweronCycle(fHistory[AIndex + 1])^.ReferenceTime;     if (ASource = UserDefinedChartSourceActualWeights) then    begin      weightT := PPoweronCycle(fHistory[AIndex + 1])^.ActualWeight / 1000;      AItem.Y := weightT;      AItem.Text := Format('%0.2f t', [weightT]);      Exit;    end;  end;end; procedure TFrameCyclesDailyWeightsHistory.ChartAxisList1MarkToText(var AText: String; AMark: Double);begin  AText := SysUtils.FormatDateTime('mmm', AMark) + System.LineEnding + SysUtils.FormatDateTime('dd', AMark);end; procedure TFrameCyclesDailyWeightsHistory.SetSource(lastStartTime: TDateTime; lastEndTime: TDateTime; history: TList; average: Pointer);begin  fLastStartTime := lastStartTime;  fLastEndTime := lastEndTime;  fHistory := history;  fAverage := average;end; /////////////////////// /////////////////////////////////////////////////////////// Translate/ ShowContent/////////////////////////////////////////////////////////// ///////////////////// procedure TFrameCyclesDailyWeightsHistory.Translate();begin end; procedure TFrameCyclesDailyWeightsHistory.ShowContent();begin  if (fHistory <> nil)     and (fHistory.Count > 0) then  begin    Chart.BottomAxis.Range.Min := fLastStartTime - 1;    Chart.BottomAxis.Range.UseMin := True;    Chart.BottomAxis.Range.Max := fLastEndTime + 1;    Chart.BottomAxis.Range.UseMax := True;    DateTimeIntervalChartSource.Params.Count :=    Math.Min(      System.Trunc(2.0 + System.Trunc((Chart.BottomAxis.Range.Max - Chart.BottomAxis.Range.Min) / 2.0) * 2.0 - 1)      , 41);     UserDefinedChartSourceActualWeights.BeginUpdate();    UserDefinedChartSourceActualWeights.Reset();    UserDefinedChartSourceActualWeights.PointsNumber := fHistory.Count - 1;    UserDefinedChartSourceActualWeights.EndUpdate();  end;end;  end.  Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i  object FrameCyclesDailyWeightsHistory: TFrameCyclesDailyWeightsHistory  Left = 0  Height = 489  Top = 0  Width = 1383  ClientHeight = 489  ClientWidth = 1383  TabOrder = 0  DesignLeft = 357  DesignTop = 112  object PanelMain: TPanel    Left = 2    Height = 435    Top = 52    Width = 1379    Align = alClient    BorderSpacing.Around = 2    BevelOuter = bvNone    ClientHeight = 435    ClientWidth = 1379    TabOrder = 0    object Chart: TChart      Left = 0      Height = 435    Top = 0      Width = 1379      AxisList = <              item        Marks.LabelBrush.Style = bsClear          Minors = <>          Range.Max = 15          Range.UseMax = True          Range.UseMin = True          Title.LabelFont.Orientation = 900          Title.Visible = True          Title.Caption = 'Weight [t]'          Title.LabelBrush.Style = bsClear        end              item        Alignment = calBottom          Marks.Alignment = taCenter          Marks.Format = '%2:s'          Marks.LabelBrush.Style = bsClear        Marks.OverlapPolicy = opHideNeighbour          Marks.Source = DateTimeIntervalChartSource          Marks.Style = smsLabel          Minors = <>          Title.Visible = True          Title.Caption = 'Days'          Title.LabelBrush.Style = bsClear          OnMarkToText = ChartAxisList1MarkToText        end>      Foot.Brush.Color = clBtnFace      Foot.Font.Color = clBlue      Legend.Alignment = laTopCenter      Legend.ColumnCount = 3      Title.Brush.Color = clBtnFace      Title.Font.Color = clBlue      Title.Text.Strings = (      'TAChart'      )      Align = alClient      object ChartBarSeriesWeights: TBarSeries        Marks.Distance = 10        Marks.LabelFont.Orientation = 900        Marks.Format = '%2:s'        Marks.Style = smsLabel        Title = 'Weight'        AxisIndexX = 1      AxisIndexY = 0        BarBrush.Color = clBlack        BarWidthPercent = 80        Source = UserDefinedChartSourceActualWeights        Stacked = False      end  end  end  object PanelChartControls: TPanel    Left = 0    Height = 50    Top = 0    Width = 1383    Align = alTop    BevelOuter = bvNone    TabOrder = 1  end  object UserDefinedChartSourceActualWeights: TUserDefinedChartSource    OnGetChartDataItem = UserDefinedChartSourceGetChartDataItem    left = 352    top = 304  end  object DateTimeIntervalChartSource: TDateTimeIntervalChartSource    Params.MaxLength = 1    Params.MinLength = 1    Params.Options = [aipUseCount, aipUseMinLength, aipUseNiceSteps]    Params.Tolerance = 1    Steps = [dtsDay]    SuppressPrevUnit = False    left = 247    top = 35  endend ---------------------------------------------------------------------- wp · 2021-12-22 10:04 The Steps property of the TDateTimeIntervalChartSource is often misunderstood. It does not mean that you want to see labels at the Steps intervals, but it means that labels are displayed only when the source advances labels in the units selected in Steps. When you allow only [dtDay] steps labels will only appear when the source is advancing the labels in day units. When you zoom into to dataset a lot the source may switch down to hour or even minute steps - but they will not be displayed because you allowed only labels for day steps. It is a good idea to not touch the Steps list for this reason. Having dtHours in the list again, however, the labels in the zoomed state may be written in the "dd hh:nn" format - but you wanted dates only. You could edit the HourFormat in the DateTimeStepFormat to become "dd mm" - but then you will see the same label several times and at unexpected positions (where the times used to appear). So - quite a mess... The TDateTimeIntervalChartSource is great to display all-purpose date/time axis labels. But it quickly becomes uncomfortable when there are special requirements. In such cases I'd recommend to replace the DateTimeIntervalChartSource by a dedicated ListChartSource which you populate with the date/time values where you need labels to appear. Write a short method which populates the source for you in full-day steps: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i procedure TForm1.UpdateDateLabels;var  ext: TDoubleRect;  d: TDate;begin  ext := Chart.LogicalExtent;  DateLabelsSource.Clear;  // DateLabelsSource is a TListChartSource added to the form and attached to BottomAxis.Marks.Source  d := trunc(ext.a.x);  repeat    DateLabelsSource.Add(d, d, FormatDateTime('dd'+LineEnding+'mmm', d));    d := d + 1.0;  until d > ext.b.x;end; Call this in the handler for the OnExtentChanged event - this fires whenever the axis range changes, for example when new data values are added, when you zoom or pan the visible viewport, or similar: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i procedure TForm1.ChartExtentChanged(ASender: TChart);begin  UpdateDateLabels;end; ---------------------------------------------------------------------- Чебурашка · 2021-12-23 08:21 Thanks for the kind explanation and code suggestion. Let me say anyway that the TAChart package is a very very very good piece of software. It is powerful and well written. Contratulations to authors and contributors.