Thursday, July 31, 2014

Creating a Google Pie Chart

As part of an exercise, i had to quickly build a chart UI which indicates number of JIRA issues assigned with the level of priority. This view is most beautiful when shown via a pie chart. Of course Core plot APIs is an option, but needed something very simpler to indicate. The search resulted in finding the Google pie chart. 

Using the playground, could visualise the chart before integrating to the application. 

The base URL for creating the chart is http://chart.googleapis.com/chart? 

The type of the chart is determined by "cht" parameter indicating the chart type.  

As part of the experiment, below are the ones tried. 

http://chart.googleapis.com/chart?cht=p3&chts=Mychart&chs=600x400&chl=January|February|March|April => Did not work 
http://chart.googleapis.com/chart?cht=p3&chs=600x400&chd=t:January,February,March,April => Did not work 
http://chart.googleapis.com/chart?cht=p3&chs=250x150&chd=t:10,20,30,40,50 => Worked, 
http://chart.googleapis.com/chart?cht=p3&chs=270x150&chd=t:10,20,30,40,50&chl=P1|P2|P3|P4 => Worked

Basically, "chd" specifies the chart data and that has to be in integer so that chart engine can slice the chart accordingly. 
the "chs" specifies the chart subject. However, could not see this appearing in the chart 
the "chl" specifies the labels of each segment. 

The chart url gives back a png image which can be displayed n a native application such as Android or iOS or within html page. 

the sample taken using the URL http://chart.googleapis.com/chart?cht=p3&chs=270x150&chd=t:10,20&chl=P1|P2&chco=FF0010,56FF00



References: 

No comments:

Post a Comment