PageRenderTime 28ms CodeModel.GetById 16ms RepoModel.GetById 1ms app.codeStats 0ms

/FusionCharts/Contents/PHPClassAPI/CombinationChart.html

https://bitbucket.org/royrutto/climatepal
HTML | 266 lines | 260 code | 6 blank | 0 comment | 0 complexity | b6edd7a933e275230423e39ebbfc22bf MD5 | raw file
  1. <?xml version="1.0" encoding="iso-8859-1"?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  2. <html xmlns="http://www.w3.org/1999/xhtml">
  3. <head>
  4. <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
  5. <title>FusionCharts v3 Documentation</title>
  6. <link rel="stylesheet" type="text/css" href="../Style.css">
  7. </head>
  8. <body>
  9. <table width="98%" border="0" cellspacing="0" cellpadding="3" align="center">
  10. <tr>
  11. <td><h2 class="pageHeader">FusionCharts PHP Class API &gt; Creating Combination Chart </h2></td>
  12. </tr>
  13. <tr>
  14. <td valign="top" class="text"><p>Combination chart has two Y-axis. The Y-axis on the left hand side is called Primary Y-Axis and that on the right hand side is called Secondary Y-Axis. Combination charts are used when we intend to compare two different types of data on the same chart, e.g., if we want to plot Weekly Sales Revenue of two consecutive months and total units sold on the same chart, we have to use a Combination Chart. See the image below and note that the two Y-axis are representing different data units. </p> </td>
  15. </tr>
  16. <tr>
  17. <td valign="top" class="text">&nbsp;</td>
  18. </tr>
  19. <tr>
  20. <td valign="top" class="text"><img src="../Images/ClassImages/ClassCombination.jpg" width="436" height="348" class="imageBorder" /></td>
  21. </tr>
  22. <tr>
  23. <td valign="top" class="text">&nbsp;</td>
  24. </tr>
  25. <tr>
  26. <td valign="top" class="text">Let's add some more data to the existing Table for Multi-series chart. We would add a column that tabulates Total Qunatity Sales. </td>
  27. </tr>
  28. <tr>
  29. <td valign="top" class="text">&nbsp;</td>
  30. </tr>
  31. <tr>
  32. <td valign="top" class="text">
  33. <table width="457" cellspacing="0" cellpadding="5" class="text" style="border:1px solid #cccccc;">
  34. <tr >
  35. <td width="25%" height="24" class="borderBottom"><strong>Week</strong></td>
  36. <td width="35%" class="borderBottom">
  37. <div align="right"><strong>Current Month </strong></div>
  38. </td>
  39. <td width="40%" class="borderBottom">
  40. <div align="right"><strong>Previous Month </strong></div>
  41. </td>
  42. <td width="40%" align="right" class="borderBottom">&nbsp;</td>
  43. </tr>
  44. <tr>
  45. <td height="22" class="borderBottom">&nbsp;</td>
  46. <td class="borderBottom">
  47. <div align="right"><strong>Sales </strong></div>
  48. </td>
  49. <td class="borderBottom">
  50. <div align="right"><strong>Sales </strong></div>
  51. </td>
  52. <td align="right" class="borderBottom"><strong>Total Quantity </strong></td>
  53. </tr>
  54. <tr>
  55. <td height="25" class="borderBottom">Week 1 </td>
  56. <td class="borderBottom">
  57. <div align="right">$40800</div>
  58. </td>
  59. <td class="borderBottom">
  60. <div align="right">$38300</div>
  61. </td>
  62. <td align="right" class="borderBottom">64</td>
  63. </tr>
  64. <tr>
  65. <td height="25" class="borderBottom">Week 2 </td>
  66. <td class="borderBottom">
  67. <div align="right">$31400</div>
  68. </td>
  69. <td class="borderBottom">
  70. <div align="right">$28400</div>
  71. </td>
  72. <td align="right" class="borderBottom">70</td>
  73. </tr>
  74. <tr>
  75. <td height="25" class="borderBottom">Week 3 </td>
  76. <td class="borderBottom">
  77. <div align="right">$26700</div>
  78. </td>
  79. <td class="borderBottom">
  80. <div align="right">$15700</div>
  81. </td>
  82. <td align="right" class="borderBottom">52</td>
  83. </tr>
  84. <tr>
  85. <td height="25">Week 4 </td>
  86. <td>
  87. <div align="right">$54400</div>
  88. </td>
  89. <td>
  90. <div align="right">$48100</div>
  91. </td>
  92. <td align="right">81</td>
  93. </tr>
  94. </table>
  95. </td>
  96. </tr>
  97. <tr>
  98. <td valign="top" class="text">&nbsp;</td>
  99. </tr>
  100. <tr>
  101. <td valign="top" class="highlightBlock"><strong>Before you go further with this page, we recommend you to please see the previous pages &quot;Creating First Chart &quot; &amp; &quot;Creating Multi-series chart&quot; as we start off from concepts explained in that page. </strong></td>
  102. </tr>
  103. <tr>
  104. <td valign="top" class="text">&nbsp;</td>
  105. </tr>
  106. <tr>
  107. <td valign="top" class="text"><p>Here is the code that builds up this Combination chart:</p></td>
  108. </tr>
  109. <tr>
  110. <td valign="top" class="text">&nbsp;</td>
  111. </tr>
  112. <tr>
  113. <td valign="top" class="codeBlock"><p>&lt;?php</p>
  114. <p> <span class="codeComment">&nbsp;&nbsp; # Include FusionCharts PHP Class</span><br />
  115. &nbsp;&nbsp; include('../Class/FusionCharts_Gen.php');</p>
  116. <p> <span class="codeComment">&nbsp;&nbsp; # Create Column 3D + Line Dual Y-Axis Combination Chart </span><br />
  117. &nbsp;&nbsp; $FC = new FusionCharts(&quot;MSColumn3DLineDY&quot;,&quot;350&quot;,&quot;300&quot;); <br />
  118. <br />
  119. <span class="codeComment">&nbsp;&nbsp; # Set the relative path of the swf file</span><br />
  120. &nbsp;&nbsp; $FC-&gt;setSWFPath(&quot;../FusionCharts/&quot;);<br />
  121. <br />
  122. <span class="codeComment">&nbsp;&nbsp; # Store chart attributes in a variable </span><br />
  123. &nbsp;&nbsp; $strParam=&quot;caption=Weekly Sales;subcaption=Comparison;xAxisName=Week;<strong>pYAxisName=Revenue;sYAxisName=Total Quantity;</strong>numberPrefix=$;<strong>sNumberSuffix</strong>= U&quot;;</p>
  124. <p> <span class="codeComment">&nbsp;&nbsp; # Set chart attributes</span><br />
  125. &nbsp;&nbsp; $FC-&gt;setChartParams($strParam);<br />
  126. <br />
  127. <span class="codeComment">&nbsp;&nbsp; # Add category names</span><br />
  128. &nbsp;&nbsp; $FC-&gt;addCategory(&quot;Week 1&quot;);<br />
  129. &nbsp;&nbsp; $FC-&gt;addCategory(&quot;Week 2&quot;);<br />
  130. &nbsp;&nbsp; $FC-&gt;addCategory(&quot;Week 3&quot;);<br />
  131. &nbsp;&nbsp; $FC-&gt;addCategory(&quot;Week 4&quot;);</p>
  132. <p> <span class="codeComment">&nbsp;&nbsp; # Add a new dataset with dataset parameters </span><br />
  133. &nbsp;&nbsp; $FC-&gt;addDataset(&quot;This Month&quot;,&quot;showValues=0&quot;); <br />
  134. <span class="codeComment">&nbsp;&nbsp; # Add chart data for the above dataset</span><br />
  135. &nbsp;&nbsp; $FC-&gt;addChartData(&quot;40800&quot;);<br />
  136. &nbsp;&nbsp; $FC-&gt;addChartData(&quot;31400&quot;);<br />
  137. &nbsp;&nbsp; $FC-&gt;addChartData(&quot;26700&quot;);<br />
  138. &nbsp;&nbsp; $FC-&gt;addChartData(&quot;54400&quot;);</p>
  139. <p> <span class="codeComment">&nbsp;&nbsp; # Add aother dataset with dataset parameters </span><br />
  140. &nbsp;&nbsp; $FC-&gt;addDataset(&quot;Previous Month&quot;,&quot;showValues=0&quot;); <br />
  141. <span class="codeComment">&nbsp;&nbsp; # Add chart data for the second dataset</span><br />
  142. &nbsp;&nbsp; $FC-&gt;addChartData(&quot;38300&quot;);<br />
  143. &nbsp;&nbsp; $FC-&gt;addChartData(&quot;28400&quot;);<br />
  144. &nbsp;&nbsp; $FC-&gt;addChartData(&quot;15700&quot;);<br />
  145. &nbsp;&nbsp; $FC-&gt;addChartData(&quot;48100&quot;);</p>
  146. <p> <span class="codeComment"><strong>&nbsp;&nbsp; </strong># Add third dataset for the secondary axis</span><br />
  147. &nbsp;&nbsp; $FC-&gt;addDataset(&quot;Total Quantity&quot;,&quot;<strong>parentYAxis=S</strong>&quot;); <br />
  148. <span class="codeComment">&nbsp;&nbsp; # Add data values</span> <span class="codeComment">for the secondary axis</span> <br />
  149. &nbsp;&nbsp; $FC-&gt;addChartData(&quot;64&quot;);<br />
  150. &nbsp;&nbsp; $FC-&gt;addChartData(&quot;70&quot;);<br />
  151. &nbsp;&nbsp; $FC-&gt;addChartData(&quot;52&quot;);<br />
  152. &nbsp;&nbsp; $FC-&gt;addChartData(&quot;81&quot;);</p>
  153. <p>?&gt;</p>
  154. <p><br />
  155. &lt;html&gt;<br />
  156. &nbsp;&nbsp; &lt;head&gt;<br />
  157. &nbsp;&nbsp; &nbsp;&nbsp; &lt;title&gt;First Chart Using FusionCharts PHP Class&lt;/title&gt;<br />
  158. &nbsp;&nbsp; &nbsp;&nbsp; &lt;script language='javascript' src='../FusionCharts/FusionCharts.js'&gt;&lt;/script&gt;<br />
  159. &nbsp;&nbsp; &lt;/head&gt;<br />
  160. &nbsp;&nbsp; &lt;body&gt;</p>
  161. <p>&nbsp;&nbsp; &nbsp;&nbsp; &lt;?php<br />
  162. <span class="codeComment">&nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; # Render Chart</span><br />
  163. &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; $FC-&gt;renderChart();<br />
  164. &nbsp;&nbsp; &nbsp;&nbsp; ?&gt;</p>
  165. <p>&nbsp;&nbsp; &lt;/body&gt;<br />
  166. &lt;/html&gt;<br />
  167. </p></td>
  168. </tr>
  169. <tr>
  170. <td valign="top" class="text">&nbsp;</td>
  171. </tr>
  172. <tr>
  173. <td valign="top" class="text"><p>As you find in the above code, creating Combination charts is similar to creating Multi-Series charts. Here too, there are multiple datasets. Some datasets are specified for primary Y-Axis and some conform to the Secondary Y-Axis.&nbsp; We need to specify which dataset belongs to which Y-Axis. Let's see how we did that in the following steps.</p>
  174. <ul type="disc">
  175. <li>We include <span class="codeInline">FusionCharts_Gen.php</span>.<br />
  176. <br />
  177. </li>
  178. <li>We create Multiseries Column 3D - Line Combination chart object and set relative path to swf file.<br />
  179. <br />
  180. <span class="codeInline"> $FC = new FusionCharts(&quot;<strong>MSColumn3DLineDY</strong>&quot;,&quot;350&quot;,&quot;300&quot;); <br />
  181. $FC-&gt;setSWFPath(&quot;../FusionCharts/&quot;);<br />
  182. </span><br />
  183. </li>
  184. <li>We store chart attributes in <span class="codeInline">$strParam</span> variable :<br />
  185. <br />
  186. <span class="codeInline">$strParam=&quot;caption=Weekly Sales;subcaption=Comparison;xAxisName=Week;pYAxisName=Revenue;<strong>sYAxisName=Total Quantity</strong>;numberPrefix=$;<strong>sNumberSuffix= U</strong>&quot;;</span><br />
  187. <br />
  188. Combination charts have 2 Y-axis -Parent (p) and Secondary (s). So we have specified names for both of them. Moreover, using <span class="codeInline">sNumberSuffix</span>, we set the number suffix for secondary Y Axis.<br />
  189. <br />
  190. </li>
  191. <li>We set these chart attributes calling <span class="codeInline">setChartParams()</span><br />
  192. <br />
  193. <span class="codeInline">$FC-&gt;setChartParams($strParam);</span><br />
  194. <br />
  195. </li>
  196. <li>Next, like in Multi-series charts we add categories :<br />
  197. <br />
  198. <span class="codeInline">$FC-&gt;addCategory(&quot;Week 1&quot;);<br />
  199. $FC-&gt;addCategory(&quot;Week 2&quot;);<br />
  200. $FC-&gt;addCategory(&quot;Week 3&quot;);<br />
  201. $FC-&gt;addCategory(&quot;Week 4&quot;);</span><br />
  202. <br />
  203. </li>
  204. <li>We add the first dataset 'This Month' for primary Y-Axis. If we do not specify the Y-Axis the dataset adheres to, the chart automatically sets it to primary Y-Axis. <br />
  205. <br />
  206. <span class="codeInline">$FC-&gt;addDataset(&quot;This Month&quot;,&quot;showValues=0&quot;); <br />
  207. $FC-&gt;addChartData(&quot;40800&quot;);<br />
  208. $FC-&gt;addChartData(&quot;31400&quot;);<br />
  209. $FC-&gt;addChartData(&quot;26700&quot;);<br />
  210. $FC-&gt;addChartData(&quot;54400&quot;);</span><br />
  211. <br />
  212. </li>
  213. <li>Again, we add another dataset 'Previous Month' for primary Y-Axis and set its attributes and data values.<br />
  214. <br />
  215. <span class="codeInline">$FC-&gt;addDataset(&quot;Previous Month&quot;,&quot;showValues=0&quot;); <br />
  216. $FC-&gt;addChartData(&quot;38300&quot;);<br />
  217. $FC-&gt;addChartData(&quot;28400&quot;);<br />
  218. $FC-&gt;addChartData(&quot;15700&quot;);<br />
  219. $FC-&gt;addChartData(&quot;48100&quot;);</span><br />
  220. <br />
  221. </li>
  222. <li>Now, we add the third dataset, this one for Secondary Y-axis and its data values. Here, we specify the Y-Axis passing the dataset attribute <span class="codeInline">parentYAxis=S</span>. <br />
  223. <br />
  224. <span class="codeInline">$FC-&gt;addDataset(&quot;Total Quantity&quot;,&quot;<strong>parentYaxis=S</strong>&quot;); <br />
  225. $FC-&gt;addChartData(&quot;64&quot;);<br />
  226. $FC-&gt;addChartData(&quot;70&quot;);<br />
  227. $FC-&gt;addChartData(&quot;52&quot;);<br />
  228. $FC-&gt;addChartData(&quot;81&quot;);</span><br />
  229. <br />
  230. </li>
  231. <li>Finally, we add <span class="codeInline">FusionCharts.js</span> and <br />
  232. <br />
  233. </li>
  234. <li> render the chart : <br />
  235. <br />
  236. <span class="codeInline">$FC-&gt;renderChart();</span></li>
  237. </ul>
  238. </td>
  239. </tr>
  240. <tr>
  241. <td valign="top">&nbsp;</td>
  242. </tr>
  243. <tr>
  244. <td valign="top" class="highlightBlock">Please go through <a href="Functions.html">FusionCharts PHP Class API Reference</a> section to know more about the functions used in the above code. </td>
  245. </tr>
  246. <tr>
  247. <td valign="top" class="text">&nbsp;</td>
  248. </tr>
  249. <tr>
  250. <td valign="top" class="text">This code renders the Combination Chart that we needed. </td>
  251. </tr>
  252. <tr>
  253. <td valign="top" class="text"><img src="../Images/ClassImages/ClassCombination.jpg" width="436" height="348" class="imageBorder" /></td>
  254. </tr>
  255. <tr>
  256. <td valign="top" class="text">&nbsp;</td>
  257. </tr>
  258. </table>
  259. </body>
  260. </html>