PHP Developers Network

A community of PHP developers offering assistance, advice, discussion, and friendship.
 
Loading
It is currently Mon Nov 18, 2019 7:45 am

All times are UTC - 5 hours




Post new topic Reply to topic  [ 13 posts ] 
Author Message
PostPosted: Fri Dec 14, 2012 12:57 pm 
Offline
Forum Contributor

Joined: Mon Dec 28, 2009 8:48 pm
Posts: 102
Hi there,
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):
Image

Can anybody guide me how to draw a area shape by php?


Top
 Profile  
 
PostPosted: Fri Dec 14, 2012 2:47 pm 
Offline
Site Administrator
User avatar

Joined: Wed Aug 25, 2004 7:54 pm
Posts: 13592
Location: New York, NY, US
I think you would probably want to use imagefilledpolygon() (http://php.net/manual/en/function.image ... olygon.php). Fill the array with the bottom points, top points and end points.

_________________
(#10850)


Top
 Profile  
 
PostPosted: Sat Dec 15, 2012 1:15 am 
Offline
Forum Contributor

Joined: Mon Dec 28, 2009 8:48 pm
Posts: 102
Thanks Christopher for your reply and suggestion. Yes, that may be a way using GD library. But there is a problem also. The array points will be derived after the calculation of the moving average (in the graph, the two solid curves in between the area shape) and the candlesticks (the red and green bars throughout the area). Actually in the picture, the upper and lower border line of the shape are constructed by +20 and -20 of the respective moving averages.

As a result the upper and lower band's array points will come after calculating the moving average (solid two curves). So I have to draw the curves and bars first, then have to draw the polygons in sequence. But, if I draw polygon after drawing the curves, it will overlap the two solid curves and the candlestick bars and those will not be seen after completion of imagecreate. 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).

My query is, is there any function by which I can draw the polygon after drawing two curves but the polygon will remain behind the curves and bars? In that situation if 'Z' order can be accomplished for polygon, it can do the thing what I expecting.

Also, there is no option for creating outline border of the area shape by imagefilledpolygon, is there?

Regards


Top
 Profile  
 
PostPosted: Sat Dec 15, 2012 11:20 pm 
Offline
Site Administrator
User avatar

Joined: Wed Aug 25, 2004 7:54 pm
Posts: 13592
Location: New York, NY, US

_________________
(#10850)


Top
 Profile  
 
PostPosted: Sun Dec 16, 2012 12:49 pm 
Offline
Forum Contributor

Joined: Mon Dec 28, 2009 8:48 pm
Posts: 102


Top
 Profile  
 
PostPosted: Sun Dec 16, 2012 4:36 pm 
Offline
Site Administrator
User avatar

Joined: Wed Aug 25, 2004 7:54 pm
Posts: 13592
Location: New York, NY, US

_________________
(#10850)


Top
 Profile  
 
PostPosted: Mon Dec 17, 2012 3:37 am 
Offline
Forum Contributor

Joined: Mon Dec 28, 2009 8:48 pm
Posts: 102
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.

By the by, is it possible to create z-order for purple area or can create masking?


Top
 Profile  
 
PostPosted: Mon Dec 17, 2012 7:28 pm 
Offline
Site Administrator
User avatar

Joined: Wed Aug 25, 2004 7:54 pm
Posts: 13592
Location: New York, NY, US

_________________
(#10850)


Top
 Profile  
 
PostPosted: Wed Dec 19, 2012 11:10 am 
Offline
Forum Contributor

Joined: Mon Dec 28, 2009 8:48 pm
Posts: 102
Hello Christopher,
Would you help in this regard if I provide you a php library that can draw area chart? There is a php class 'chart.php' which draw this area chart. But I am dull in understanding php class. Would you tell me by which method (imagefilledrectangle/imagefilledpolygon etc) this library is drawing area chart?

I have attached the library with this reply and the web address of this library is:


Please help me finding the method if you have time.

Regards


Attachments:
chart-0.8.tar.gz [38.32 KiB]
Downloaded 1356 times
Top
 Profile  
 
PostPosted: Wed Dec 19, 2012 3:08 pm 
Offline
Site Administrator
User avatar

Joined: Wed Aug 25, 2004 7:54 pm
Posts: 13592
Location: New York, NY, US
Please provide the code that draws the graph in the first post. And and an example data set for the number of days on that chart. Thanks.

_________________
(#10850)


Top
 Profile  
 
PostPosted: Thu Dec 20, 2012 12:20 am 
Offline
Forum Contributor

Joined: Mon Dec 28, 2009 8:48 pm
Posts: 102
Dear Chritopher
Thanks for your reply. I don't have the code of first post, because that picture is from another site. I am trying to code for that type of chart. I have my own code which pulls data from my mysql table (which creates chart only for moving average). If you want, I can send you the code by email or by PM (if possible).
But in the previous post, the attached post contain data and necessary codes for area chart. After unzip the attached file, you may find data array from data.php and area chart code from example12.php and the class file which can produce area chart from chart.php.

You may also view demo of area chart from the link below:


Thanks


Top
 Profile  
 
PostPosted: Thu Dec 20, 2012 10:17 am 
Offline
Site Administrator
User avatar

Joined: Wed Aug 25, 2004 7:54 pm
Posts: 13592
Location: New York, NY, US
I can look at example12.php, but if you can post you own example it would be better. They both you and I, and others, can work through the problem.

_________________
(#10850)


Top
 Profile  
 
PostPosted: Thu Dec 20, 2012 1:08 pm 
Offline
Forum Contributor

Joined: Mon Dec 28, 2009 8:48 pm
Posts: 102
Hi Christopher,
I PM my code to you. Please check your private message (PM). Also, please don't quote the code here in this topic. Just discuss any matter indirectly here. If you want to ask in details for any part of my code, it will be my pleasure if you PM me.


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 13 posts ] 

All times are UTC - 5 hours


Who is online

Users browsing this forum: No registered users and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Jump to:  
Powered by phpBB® Forum Software © phpBB Group