I can draw bar and line graph by php using gd library. But cant find a way to draw a area chart like below (here the area of violet color):

Can anybody guide me how to draw a area shape by php?
Moderators: onion2k, General Moderators

I can't imagine that there would be a "huge memory consumption" storing maybe 100 arrays of 8 x,y pairs. You're building images in memory and worring about an array of integers?!? PHP programs fetch 100+ database records that are bigger than that without thinking twice. And not sure why you'd need to store all the values of the bars on the first pass anyway -- they are all the same width. Sounds like Premature Optimization. I'd pre-process the data and build the image in layers back to front. Then see if there is a real memory problem.infomamun wrote:And If I store the x,y coordinates of curves and candlestick bars by variables for drawing after polygons, there will be a huge memory consumption as there will be lots of x,y coordinate points for two curves and specially for candlestick bars (for each bar, there are 8 x,y coordinate values).
for each bar, there are four x,y coordinates (x1,x2,y1,y2) and you might have noticed that there are two threads/sticks attached with each candlestick bar, for those you need more 2x2=4 coordinates. Although bars are of same width but not of same height. So there will be total 8 coordinates for each bar. Additionally if you want border around each bar, there will be atleast 4 coordinates more.Christopher wrote:And not sure why you'd need to store all the values of the bars on the first pass anyway -- they are all the same width. Sounds like Premature Optimization.
Yes I am worried, because I have a shared hosting in which almost all pages are dynamic. It scraps pages from a stock market website and shows in a simpler format. Thus it creates a heavy load on shared server. Few days ago, I was bound to restrict some of my pages by login system as my site was suspending for using over-resources (only 15% CPU usage). So I try to use as much simpler code as I can. I even don't use more than two/three include files in one page to reduce http requests per page.Christopher wrote:You're building images in memory and worring about an array of integers?!?
I understand that you need to calculate those coordinates when you draw the bars, but that is a later pass. I assume you are starting with a high/low or open/close values for each day. On the first pass you draw the grid. Then you want to draw the purple area. You don't need the coordinates for the bars yet -- just the the top and bottom of the purple area for that day. Once you draw the purple area, then calculate the coordinates for the bars and draw the bars.infomamun wrote:for each bar, there are four x,y coordinates (x1,x2,y1,y2) and you might have noticed that there are two threads/sticks attached with each candlestick bar, for those you need more 2x2=4 coordinates. Although bars are of same width but not of same height. So there will be total 8 coordinates for each bar. Additionally if you want border around each bar, there will be atleast 4 coordinates more.
My point was that you could calculate just what is needed on each pass -- as you were concerned about creating arrays for some reason.infomamun wrote:Actually purple area is not directly related with bars, but with moving average (the two solid curves inside purple area). Moving Averages are calculated in each minute and upper and lower bottom of purple area are calculated by the following formula:
Upper point = Moving Average+20% of Moving Average
Lower point = Moving Average-20% of Moving Average
The whole trade hour per day is about 4hrs, that means there are 4x60=240 minutes and in each minute I have to calculate moving averages and upper and lower point of purple areas. So, if I can draw moving averages and purple area at the same time, it can reduces task and memory consumption.
Not that I know of.infomamun wrote:By the by, is it possible to create z-order for purple area or can create masking?