proper xaxis application lazarus / 55-TAChart ---------------------------------------------------------------------- frederic · 2015-08-11 14:38 dear specialists, i applied the concept of the earlier thread on this subject but ran into several errors.( e.a .edrawerror,dataleaks  etc) So i prepared a testproject to demonstrate this But also there i ran into the problem that i couldn't show the values of the x-axis labels although all "visible"-properties were true. this has to be solved first in order to show the other issues can someone give me a hint? attached the testproject in included frederic ---------------------------------------------------------------------- wp · 2015-08-11 15:24 Sorry I dont't want to sound arrogant, but I don't have enough time to step through 1000 lines of poorly formatted code to understand what may be wroing without knowing what is wrong. You should precisely describe the steps to reproduce the issue that you see. Which buttons to click, in which order, any input required, and what do you expect in which situation of the program? ---------------------------------------------------------------------- frederic · 2015-08-12 14:06 Wp ,  when i reread my question i can understand your reaction ;you are right; i can compress it I changed the testproject( see new one attached) a little bit.So forget my former testproject When you start up the project ,click “makegraph “button on the toolbar. The  graphfrm will show up with chart1 on it. The “chart”of the Xaxisseries is the horizontal line with value 5 . The values for the xaxis are not shown although the values are known in the timechartsource and the datechartsource. That is problem i couldn't solve. but let me also explain a little bit further: The difference with the earlier thread is that now everything is derived from socalled bars( time increments from 1 min (here in the testproject)  to 200 min or more). The Xaxis should be presented as you have shown in the former thread.  The bars position is determined by the “days”variable; An extra complication ,that is introduced ,is the possibility that the opening hours per day may vary and we have specialdays ( often the Monday,but also other days, are not a working days or not full working days) The feederunit  in the project (for simplicity,now set with a fixed opening and closing)will take care of all that and present  bar arrays from which the dt -data, daybegin,weekbegin and monthbegin  will be derived in order to construct the Xaxis .  This the reason why i am modifying the “updatelabels” procedure and it but becomes more complicated . frederic ---------------------------------------------------------------------- wp · 2015-08-12 15:56 After setting a breakpoint at the end of the UpdateAxisLabels method I see that the method always ends with AChartSource.Count = 0. This seems to originate in the line "if dt > 1" because in the line before that you get "dt" from the element FdubDTTime[0] which has not been initialized in "SetGraphXaxisArray22" and has the value 0 (your init loop runs from 1 to n, but dynamic arrays are 0-based). I am not sure if this is the main cause of your issue, but I think I cannot help you in more detail because this would require in-depth understanding of your code. Use the debugger to step through every line of every procedure, or add "WriteLn" calls to check temporary values of more complex variables which the debugger cannot resolve,  and compare each value with what you would expect. ---------------------------------------------------------------------- frederic · 2015-08-13 15:19 ooh , i had played around with  the starting conditions. your suggestion to use writeln calls mixed me up in other kind of issue',not for this thread. i will come back when i am further. thanks so far frederic ---------------------------------------------------------------------- wp · 2015-08-13 17:08 Quote from: frederic suggestion to use writeln callsJust in case you don't know if you are on Windows and want to write to the console: Calling "WriteLn" from the gui requires to uncheck the "Win32 gui application" in the "Project options" / "Compiler options" / "Config and target" / "Target-specific options" ---------------------------------------------------------------------- wp · 2015-08-13 19:57 Let me summarize your description in my own words to make sure that I understand everything and remember to other thread correctly: Your x data are equally spaced, at some predefined intervals (minutes) - is that what you call "bars"? Data are collected / available only during a given time interval per day (beginning at "FOpeningTimeArr[]" and ending at "FClosingTimeArr[]", and only on working days (i.e. normally between Mo and Fr, except for some holidays known to the program) There are two x axes: a coarse one labelled by date, and a fine one labelled by times. Labels must not be drawn in the data gaps (time between closingtime of one day and openingtime of the next day, non-working days), i.e. a line series must not show a x gap over the weekend and over night. In a line series, can the last data point of a day be connected with the first data point of the next day? Or do you want only the contiguous data of each day be connected? Labels must adapt to zooming and chart resizing. For example, at larger magnification, the label interval should become smaller Labels must not overlap and must be "nice" numbers (i.e. every 10 minutes, not every 13.5 minutes, or every 2 days, not every 2.5 days)Please define the "nice" intervals for the dates and times. I'd propose - date interval: 1 day, 2 days, 7 days, 1 month, 2 months, 3 months - time intervals: 6 hours, 3 hours, 2 hours, 1 hour, 30 min, 15 min, 10 min, 5 min, 1 minA question to your program (maybe I have asked it already in the other thread): Why do you have an xaxisseries? ---------------------------------------------------------------------- frederic · 2015-08-15 20:17 Wp ,i am sorry not to react earlier, QuoteJust in case you don't know if you are on Windows and want to write to the console: Calling "WriteLn" from the gui requires to uncheck the "Win32 gui application" in the "Project options" / "Compiler options" / "Config and target" / "Target-specific options" i tried that, but the console creen remained black !   I started an other thread in the general forum,which solved the problem in an acceptable way. But I learned the advantage of using writewln calls instead of memo because  one can use it anytime also in units without form.  Disadvantage, however it appeared ,that one has to open and close the file in the same function/procedure. QuoteYour x data are equally spaced, at some predefined intervals (minutes) - is that what you call "bars"?  Oh ,I see ,I need to be more specific about my intentions. The  Y-data  which will be displayed in the chart will be based on  chosen  multiminute time increment. However not all sizes of  time increments will fit exactly between opening and closing time on a day .So i decided that the size of all time increment the day will be kept the same exept the last one. The last timeincrement on a day may be increased to maximum 1.50001 times the choosen time increment. For x-axis value display this will have no consequenses ; the X-value of all XY data is a “double”value based on the “daysvalue” as in the earlier thread. QuoteData are collected / available only during a given time interval per day (beginning at "FOpeningTimeArr[]" and ending at "FClosingTimeArr[]", and only on working days (i.e. normally between Mo and Fr, except for some holidays known to the program) yes QuoteThere are two x axes: a coarse one labelled by date, and a fine one labelled by times.yes  For the display there are these 2 axes. The most important;however, is the most important is the virtual one ,the 'days' variable (see former thread).All chart data will arrive as x,y  = days, yvalue. QuoteLabels must not be drawn in the data gaps (time between closingtime of one day and openingtime of the next day, non-working days), i.e. a line series must not show a x gap over the weekend and over night. In a line series, can the last data point of a day be connected with the first data point of the next day?   Yes QuoteOr do you want only the contiguous data of each day be connected? No QuoteLabels must adapt to zooming and chart resizing. For example, at larger magnification, the label interval should become smaller yes QuoteLabels must not overlap and must be "nice" numbers (i.e. every 10 minutes, not every 13.5 minutes, or every 2 days, not every 2.5 days) yes,dateinterval     1 day,                           1 week(starting first workday in week,ending last workday in week) ,                           1 month(starting first workday in month,ending last workday in month)      time interval      1 min,5 min,10 min,60 min ,120 min The original reason for the use of Xaxisseries is the requirement to be able to see the xaxis also beyond the current available XY chart data. By deriving the values by using the crosshair ,it can be a great help  with preparation of designing  possible projections . It offers further greater flexibility  and accuracy then to base everything on bars . frederic ---------------------------------------------------------------------- wp · 2015-08-15 21:44 Ah, I forgot: Opening and closing times are always the same? Or could it be that, for example on New Year's Eve, closing occurs earlier? ---------------------------------------------------------------------- frederic · 2015-08-16 09:53 wp opening and closingtimes  are not always the same. therefore FOpeningTimeArr[]" and "FClosingTimeArr[] are part of input for procedure SETgraphXaxisarray22. So per workday opening and closingtimes are known. b.t.w both arrays are integer arrays show the minuteof theday frederic ---------------------------------------------------------------------- wp · 2015-08-16 11:50 Storing opening/closing times in an array will make a labelling procedure very unflexible. If your program stores them for this year then your program won't work any more in 2016! Is there a way to determine the opening/closing time for a specific day? I am thinking of using the first data point of a day for the opening time and the last data point for the closing time. Quoteb.t.w both arrays are integer arrays show the minuteof thedayYou mean that these times are given as the count of minutes after midnight? Why that? Why don't you use TTime? ---------------------------------------------------------------------- frederic · 2015-08-16 14:47 QuoteIs there a way to determine the opening/closing time for a specific day? I am thinking of using the first data point of a day for the opening time and the last data point for the closing time. so i started also,but was confronted with the fact it may be that not every first minute or last minute was filled with data ; unfortunately ,there are gaps in the data supply. Therefore I had to make sure that the timeline (the axis is always complete) otherwise the basis for making good projections would fail .Having said that ,i realised that an axis based on the smallest timeincrement available(1 minute) ,would be the best solution;  Even better than the " days"variable. The feederunit will get its opening and closing times from a special Times-unit. This unit can make a file per year which lists 365 days indicating per day :workday (or not) with opening and closing minute per day. When opening/closingtimes of a shop change that can easily be corrected in the list .Of course ,each year has its own specific list and needs to be updated according to the latest knowledge QuoteYou mean that these times are given as the count of minutes after midnight? Why that? Why don't you use TTime? yes,these times are given as the count of minutes after midnight you can use TTtime as well ,but in my case a lot of the calculations were based on minutes ---------------------------------------------------------------------- wp · 2015-08-16 15:15 Quote making good projectionsHuh, what's that? Do you want to make a trend analysis, fit a curve? Fiddling with gaps in the data will affect the result. So far, I had the impression that you only want a "nice" x axis. Still under the assumption that this is an axis labelling topic: What is the problem if the "official" opening time is 9:00, but the first data set is available only at 9:02. The axis labels of this day still can begin at 9:00. What if such gaps occur during the day? Sorry for all these questions. But I am thinking of finding a more general solution (although I fear that your requirements are too special) ---------------------------------------------------------------------- frederic · 2015-08-17 08:39 yes ,it is still the nice x-axis question without overlapping labels during zooming but also, yes as i explained , this x-axis will be used in an application were trend analysis will be made. So the  construction of the xaxis should should not be affected by the the wish to have no overlapping . QuoteWhat is the problem if the "official" opening time is 9:00, but the first data set is available only at 9:02. The axis labels of this day still can begin at 9:00. as long the labeling starts and ends at the right times  every day then it ist oke. But to make it clearer: a day1 (FROM 9-18 H) and day2( 9-12h) need to have a different x-axis spacing . I see that the range of shop opening hours range from 5 to 14 hours; this might change the overlapping rules for the date-time labels QuoteSorry for all these questions. But I am thinking of finding a more general solutionit is better to explain what and why I want to change certain things; when it goes too far then i have to step back and accept that overlapping in certain situations is unavoidable. frederic ---------------------------------------------------------------------- wp · 2015-08-17 17:35 Coming back to your program: Did you follow the input with the unitialized  FdubDTTime[0]? This originates in the line "for n:=1 to Ffutmaxbars do ..." of Tstdchartfrm.SetGraphXaxisArray22 where n := 0 is not used. Moreover, there is another missing assignment for the index 0 in TForm1.makeXaxarray. Here "mm" is set to 0, and later incremented by 1 ("mmm:=mmm+1") before a value is assigned to "FDTXAxarr1[mmm]", i.e. FDTXAxarr1[0] is never touched. And in the before-mentioned SetGraphXaxisArray22 this array serves as the source for FdubDTTime. The axis labels show up after initializing "mm" with -1, and starting the n loop of the first paragraph with 0. As I said before, all these details are very confusing to me, and I am not going to find all these logical bugs for you, they are not related to TAChart - sorry. Just one hint: Before getting the axis labels right, fix all these issues on the basis of your "virtual" axis units. What I can offer is to try to improve the TDateTimeIntervalChartSeries to get nicer axis labels for the average application, but I am almost sure that this will not fix your very special requirements. ---------------------------------------------------------------------- frederic · 2015-08-18 14:19 QuoteComing back to your program: Did you follow the input with the unitialized  FdubDTTime[0]? This originates in the line "for n:=1 to Ffutmaxbars do ..." of Tstdchartfrm.SetGraphXaxisArray22 where n := 0 is not used. Moreover, there is another missing assignment for the index 0 in TForm1.makeXaxarray. Here "mm" is set to 0, and later incremented by 1 ("mmm:=mmm+1") before a value is assigned to "FDTXAxarr1[mmm]", i.e. FDTXAxarr1[0] is never touched. And in the before-mentioned SetGraphXaxisArray22 this array serves as the source for FdubDTTime. I had discovered this also and corrected it.The testproject must be completely in line with the application i am developing .It could easily be that these issues may be the reason for the strange errors i got there.I must check that first and otherwise rewrite  the test project. with regard to the very special requirements i have an idea. In the way you normally would set up an x-axis it is likely very compllicated. But you already showed a way to come around it by having an overlap and a delta calculation procedure(see your code in the former thread). I am thinking of extending the use of the xaxisarrays in my setXaxisarray procedure.There  we could prepare label arrays for Timechartsource and Datechartsource per  "nice step".This done once per session. We know which labels we want and  and where they need to be located. Irregular opening times  are now  taken already care of , because the arrays are based on the real minutes. The total theoretical  pixel length of of all the labels together can be calculated .Together with the current extent of the chart we can calculate  max number of minutes( xaxisarrays are minutes)  per "nice step ",which are allowed to be shown on the xaxis .( datelabels are to be based on the smallest day in the arrays) ps instead of having separate arrays may be you can have Timechartsource1,Timechartsource2,...etc,. I don't know what is easier. This could also be a general approach like with histograms were you can have arbitrary text per bar( i don't know how  that is done in lazarus) But for the moment leave it,because i cannot react in the coming days and i will check my program first frederic ---------------------------------------------------------------------- frederic · 2015-09-04 20:26 wp i checked my application and some weird hussling with arrayhandling was  the reason for the strange errors. I stopped it and worked out the idea i mentioned in my former thread . Although very simple coded by a dummie  i wrote a testproject  but  it worked  okay. When you are interested i can send it here frederic ---------------------------------------------------------------------- wp · 2015-09-04 22:48 Quote from: frederic on September 04, 2015, 10:26:15 pmWhen you are interested i can send it here Yes please ---------------------------------------------------------------------- frederic · 2015-09-05 11:07 wp the testproject is attached just before sending i saw that the turn off of the markation lines did not function as i intended frederic