Search code examples
delphiteechart

Delphi Tchart leftaxis time labels


I would like to use a TChart to evaluate times. (like 1:12; 1:15; 1:13; ...) For this I would like to show the experiments (1,2,3 ...) on the X-axis. The Y-axis should be a time legend. (as seen in the photo on the X-axis). Unfortunately, I succeed only on the X-axis.

The time legend I wish on the Y-axis

The time legend I wish on the Y-axis

What I tried:

procedure kMyDiagram.config;
Begin
    mychart.LeftAxis.LabelStyle := taltext;
    DataLine:=TLineSeries(MyChart.Series[0]);
end;

procedure kMyDiagram.myDiagramMouseDown(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer)
begin
    timecounter:=timecounter +10;
    time:=strtotime('00:0'+ timecounter);
    DataLine.AddXY(DataLine.XScreenToValue(x),DataLine.YScreenToValue(y),timetostr(time));
end;

This creates something like that... Time Labels at Y-Axis but also at X-Axis(and there should be integers like 1,2,3...)

Time Labels at Y-Axis but also at X-Axis(and there should be integers like 1,2,3...)

So how can I make this custom Y-Axis?

Thanks in advance for your answer.


Solution

  • I created new TChart with TLineSeries, and made the only setting: Series1-General-Vertical Axis-DateTime checkbox.

    Now code below produces chart with 0..7 labels on X axis and 0:00, 0:30...7:00 labels on Y axis (1/24 is one hour)

    var
      i: integer;
    begin
      for i := 0 to 7 do
        Series1.AddXY(i, (i * i) / 7 * 1/24);