Forum > TAChart

[Solved] Chart DateTime Axis with Hours only has too many values

<< < (2/2)

Wilko500:
Thank you for that tip, ctrl click in IDE. That will get used in the future.  I got Math for procedure SameValue from Google. It's often first point of call.  I note that I am often offered Google's AI attempt at answering programming questions.  While it is not perfect and its code snippets are often lacking it will usually give a good idea of how to fix a problem and that often leads to further search clues. 

Wilko500:
@wp, an update.  It's taken me a while to get back to this having been sidetracked by memory leaks.  Your code snippet was very helpful.  I decided to try it out with values other than 4 and found that for example with 2 the last label was not displayed.  I spent a while trying to figure out why but did not find a complete solution.  I think it was the loop test that didn't actually find the last value so label not displayed.  I also tried changing the precision value but that didn't help me. 
Then I changed the loop test and added an additional line after the loop finished.  The result was code that will do any value between 2 and 23.  The last label is always displayed, see pic with hour interval = 5.  In the code aChtRec is a record containing chart parameters so a single CreateCharts procedure can create all 7 of my charts. Thank you :)

As a side note being able to force the last label to always be drawn was on my todo list so you actually solved two problems for me.

--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---Procedure PopulateTimeLabels(ARange: TChartRange; AListChartSource:TListChartSource; AChtRec: ChartRec);var  dt: TDateTime;begin  AListChartSource.BeginUpdate;  try    AListChartSource.Clear;    // Iterate over the range    dt := ARange.Min;    while dt <= ARange.Max do    begin      If SameDateTime(dt, ARange.Max) Then       // Form1.ListChartSource1.Add(dt, 0, '24')     // Without this the last time label would be '0' which looks strange to me under these circumstances      else        AListChartSource.Add(dt, 0, FormatDateTime('h', dt));//      dt := dt + 2/24;    // Advance dt in 4-hour steps      dt := dt + AChtRec.HrSteps/24;    // Advance dt in 4-hour steps    end;    AListChartSource.Add(ARange.Max, 0, '24')   //Needs this for 2 hr steps else no label  finally    AListChartSource.EndUpdate;  end; End;{Procedure PopulateTimeLabels}  

Navigation

[0] Message Index

[*] Previous page

Go to full version