Getting Started Tutorial on PHP Generating Chart pChart_PHP Tutorial is an open source chart generation library, mainly involving 3 Classes: Getting Started Tutorial on PHP Generating Chart pChart_PHP Tutorial.class, pData.class, pCache.class, which can be generated More than 20 simple or complex charts, supporting PNG, JPG, GIF common image formats. The data source can come from Database, CSV, or handwritten. To use PHP, you need to enable the GD service. Let’s take a look at the workflow of Getting Started Tutorial on PHP Generating Chart pChart_PHP Tutorial first:
It is mainly divided into three steps:
Look at a simple bar chart below:
The code is as follows:
<span style="color: blue"><?php </span><span style="color: green">// Standard inclusions </span><span style="color: blue">include</span><span style="color: purple">(</span><span style="color: olive">"Getting Started Tutorial on PHP Generating Chart pChart_PHP Tutorial/pData.class"</span><span style="color: purple">)</span>; <span style="color: blue">include</span><span style="color: purple">(</span><span style="color: olive">"Getting Started Tutorial on PHP Generating Chart pChart_PHP Tutorial/Getting Started Tutorial on PHP Generating Chart pChart_PHP Tutorial.class"</span><span style="color: purple">)</span>; <span style="color: green">// Dataset definition </span><span style="color: blue">$DataSet </span><span style="color: purple">= </span><span style="color: blue">new </span>pData; <span style="color: green">//图表数据 </span><span style="color: blue">$DataSet</span><span style="color: purple">-></span>AddPoint<span style="color: purple">(</span><span style="color: blue">array</span><span style="color: purple">(</span><span style="color: red">1</span><span style="color: purple">,</span><span style="color: red">4</span><span style="color: purple">,-</span><span style="color: red">3</span><span style="color: purple">,</span><span style="color: red">2</span><span style="color: purple">,-</span><span style="color: red">3</span><span style="color: purple">,</span><span style="color: red">3</span><span style="color: purple">,</span><span style="color: red">2</span><span style="color: purple">,</span><span style="color: red">1</span><span style="color: purple">,</span><span style="color: red">0</span><span style="color: purple">,</span><span style="color: red">7</span><span style="color: purple">,</span><span style="color: red">4</span><span style="color: purple">),</span><span style="color: olive">"Serie1"</span><span style="color: purple">)</span>; <span style="color: blue">$DataSet</span><span style="color: purple">-></span>AddPoint<span style="color: purple">(</span><span style="color: blue">array</span><span style="color: purple">(</span><span style="color: red">3</span><span style="color: purple">,</span><span style="color: red">3</span><span style="color: purple">,-</span><span style="color: red">4</span><span style="color: purple">,</span><span style="color: red">1</span><span style="color: purple">,-</span><span style="color: red">2</span><span style="color: purple">,</span><span style="color: red">2</span><span style="color: purple">,</span><span style="color: red">1</span><span style="color: purple">,</span><span style="color: red">0</span><span style="color: purple">,-</span><span style="color: red">1</span><span style="color: purple">,</span><span style="color: red">6</span><span style="color: purple">,</span><span style="color: red">3</span><span style="color: purple">),</span><span style="color: olive">"Serie2"</span><span style="color: purple">)</span>; <span style="color: blue">$DataSet</span><span style="color: purple">-></span>AddPoint<span style="color: purple">(</span><span style="color: blue">array</span><span style="color: purple">(</span><span style="color: red">4</span><span style="color: purple">,</span><span style="color: red">1</span><span style="color: purple">,</span><span style="color: red">2</span><span style="color: purple">,-</span><span style="color: red">1</span><span style="color: purple">,-</span><span style="color: red">4</span><span style="color: purple">,-</span><span style="color: red">2</span><span style="color: purple">,</span><span style="color: red">3</span><span style="color: purple">,</span><span style="color: red">2</span><span style="color: purple">,</span><span style="color: red">1</span><span style="color: purple">,</span><span style="color: red">2</span><span style="color: purple">,</span><span style="color: red">2</span><span style="color: purple">),</span><span style="color: olive">"Serie3"</span><span style="color: purple">)</span>; <span style="color: blue">$DataSet</span><span style="color: purple">-></span>AddAllSeries<span style="color: purple">()</span>; <span style="color: blue">$DataSet</span><span style="color: purple">-></span>SetAbsciseLabelSerie<span style="color: purple">()</span>; <span style="color: green">//数据图例 </span><span style="color: blue">$DataSet</span><span style="color: purple">-></span>SetSerieName<span style="color: purple">(</span><span style="color: olive">"Microsoft"</span><span style="color: purple">,</span><span style="color: olive">"Serie1"</span><span style="color: purple">)</span>; <span style="color: blue">$DataSet</span><span style="color: purple">-></span>SetSerieName<span style="color: purple">(</span><span style="color: olive">"IBM"</span><span style="color: purple">,</span><span style="color: olive">"Serie2"</span><span style="color: purple">)</span>; <span style="color: blue">$DataSet</span><span style="color: purple">-></span>SetSerieName<span style="color: purple">(</span><span style="color: olive">"Google"</span><span style="color: purple">,</span><span style="color: olive">"Serie3"</span><span style="color: purple">)</span>; <span style="color: green">// Initialize the graph </span><span style="color: blue">$Test </span><span style="color: purple">= </span><span style="color: blue">new </span>Getting Started Tutorial on PHP Generating Chart pChart_PHP Tutorial<span style="color: purple">(</span><span style="color: red">700</span><span style="color: purple">,</span><span style="color: red"> 230</span><span style="color: purple">)</span>; <span style="color: green">//Set chart size and style </span><span style="color: blue">$Test</span><span style="color: purple">-></span>setFontProperties<span style="color: purple">(</span><span style="color: olive">"Fonts/tahoma.ttf"</span><span style="color: purple">,</span><span style="color: red">8</span><span style="color: purple">)</span>; <span style="color: blue">$Test</span><span style="color: purple">-></span>setGraphArea<span style="color: purple">(</span><span style="color: red">50</span><span style="color: purple">,</span><span style="color: red">30</span><span style="color: purple">, </span><span style="color: red">680</span><span style="color: purple">,</span><span style="color: red">200</span><span style="color: purple">)</span>; <span style="color: blue">$Test</span><span style="color: purple">-></span>drawFilledRoundedRectangle<span style="color: purple">(</span><span style="color: red">7</span><span style="color: purple">,</span><span style="color: red">7</span><span style="color: purple">, </span><span style="color: red">693 <p align="left"></p> <div style="display:none;"> <span id="url" itemprop="url">http://www.bkjia.com/PHPjc/486322.html</span><span id="indexUrl" itemprop="indexUrl">www.bkjia.com</span><span id="isOriginal" itemprop="isOriginal">true</span><span id="isBasedOnUrl" itemprop="isBasedOnUrl">http: //www.bkjia.com/PHPjc/486322.html</span><span id="genre" itemprop="genre">TechArticle</span><span id="description" itemprop="description">Getting Started Tutorial on PHP Generating Chart pChart_PHP Tutorial is an open source chart generation library, mainly involving 3 Classes: Getting Started Tutorial on PHP Generating Chart pChart_PHP Tutorial.class, pData.class, pCache .class, can generate more than 20 simple or complex charts, supporting PNG, JPG, GIF...</span> </div> <div class="art_confoot"></div></span></span>