PHP Developers Network
http://forums.devnetwork.net/

How to create area chart by php
http://forums.devnetwork.net/viewtopic.php?f=40&t=137173
Page 1 of 1

Author:  infomamun [ Fri Dec 14, 2012 12:57 pm ]
Post subject:  How to create area chart by php

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?

Author:  Christopher [ Fri Dec 14, 2012 2:47 pm ]
Post subject:  Re: How to create area chart by php

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.

Author:  infomamun [ Sat Dec 15, 2012 1:15 am ]
Post subject:  Re: How to create area chart by php

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

Author:  Christopher [ Sat Dec 15, 2012 11:20 pm ]
Post subject:  Re: How to create area chart by php


Author:  infomamun [ Sun Dec 16, 2012 12:49 pm ]
Post subject:  Re: How to create area chart by php


Author:  Christopher [ Sun Dec 16, 2012 4:36 pm ]
Post subject:  Re: How to create area chart by php


Author:  infomamun [ Mon Dec 17, 2012 3:37 am ]
Post subject:  Re: How to create area chart by php

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?

Author:  Christopher [ Mon Dec 17, 2012 7:28 pm ]
Post subject:  Re: How to create area chart by php


Author:  infomamun [ Wed Dec 19, 2012 11:10 am ]
Post subject:  Re: How to create area chart by php

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 1419 times

Author:  Christopher [ Wed Dec 19, 2012 3:08 pm ]
Post subject:  Re: How to create area chart by php

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.

Author:  infomamun [ Thu Dec 20, 2012 12:20 am ]
Post subject:  Re: How to create area chart by php

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

Author:  Christopher [ Thu Dec 20, 2012 10:17 am ]
Post subject:  Re: How to create area chart by php

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.

Author:  infomamun [ Thu Dec 20, 2012 1:08 pm ]
Post subject:  Re: How to create area chart by php

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.

Page 1 of 1 All times are UTC - 5 hours
Powered by phpBB® Forum Software © phpBB Group
http://www.phpbb.com/