Charting stock price crashes. lazarus / 55-TAChart ---------------------------------------------------------------------- jw · 2012-01-25 04:25 been trying to learn to plot charts and am finding it to be quite challenging. my program is a stock symbol charting program, I download a csv file for a stock to plot on my chart.  The csv file contains Date,open,High,Low,Close,Volume,Adj Close I setup my chart to plot datetime on x axis, price in left y axis volume in right y axis.  the problem, when I populate the chart by loading the stock price and datetime from the file the program takes 99% resources for a long time then plots a very funny set of lines that look more like an area chart drawing then a line chart. atttached is the original program and a modified one basically a stripped down version of the examples axis program since I couldn't make my original code work I thieved as much as I could from the example to try and learn my mistakes.   Both programs end up doing the same thing so I’ve not learned anything. laz version 0.9.30 fpc 2.4.2 the projects were to big to attach but can be found here. http://jwfiledump.webuda.com/jwstock.zip this is the project I’d like to continue development with since everything in it I did by hand http://jwfiledump.webuda.com/modded_demo.zip this is the modded demo originally axis demo I stripped and stripped until I was left with the bare of what I thought I needed.  This version pans where the original program above can’t but again I’d rather continue developing with the jwstock project since I think I know what’s happening with everything there and need to learn to pan by settings through the IDE rather then cut and past components from the examples. ---------------------------------------------------------------------- Ask · 2012-01-25 07:25 Your desire to learn is commendable. However, before you jump to drawing charts, I would recommend to learn more about basic programming techniques, such as source code formatting, loops, date and string manipulation, data structures and algorithmic complexity. After you will get well versed in the above, you will find that the answer to your current question magically became obvious ;-) Nevertheless, the most important problem in your code is that not only you use O(n^2) algorithm to read the data, you also move it into a chart inside the reading loop. Resulting complexity is O(n^2) in both time *and* memory, which is quite a lot for your n=200000. (Additionally, you use O(line_length^2) parsing algorithm, but that inefficiency is negligible compared to the main one above). The second problem is that you did not enforce date and numeric formatting, so, for example, on my PC you program crashed immediately with the format error. The third problem is that your code is formatted inconsistently, with many spurious empty lines and comments, so it took a (relatively) long time for me to remove them before I was able to understand what are you doing. Finally, the fourth problem is really related to a TChart: you should set Marks.Style=smsLabel to display formatted dates on the bottom axis. ---------------------------------------------------------------------- jw · 2012-01-25 19:56 found the nested loop the rest I'm still trying to learn thanls ask