PHP图表制作库,PHPlot 5.6.0 发布,

fmms 13年前
     <p><a style="font-weight:bold;" href="/misc/goto?guid=4958323561219070566" target="_blank">PHPLOT </a>是一个用来创建图表的PHP图形类,需要 PHP5 的支持。PHPLot使用PHP的GD扩展来生成 PNG/GIF/JPEG 格式图片。</p>    <p>生成上面图形的代码如下:</p>    <p><code><span style="color:#000000;"><span style="color:#ff8000;"># PHPlot Demo<br /> # 2008-01-09 ljb<br /> # For more information see http://sourceforge.net/projects/phplot/<br /> <br /> # Load the PHPlot class library:<br /> </span><span style="color:#007700;">require_once </span><span style="color:#dd0000;">'phplot.php'</span><span style="color:#007700;">;<br /> <br /> </span><span style="color:#ff8000;"># Define the data array: Label, the 3 data sets.<br /> # Year,  Features, Bugs, Happy Users:<br /> </span><span style="color:#0000bb;">$data </span><span style="color:#007700;">= array(<br />   array(</span><span style="color:#dd0000;">'2001'</span><span style="color:#007700;">,  </span><span style="color:#0000bb;">60</span><span style="color:#007700;">,  </span><span style="color:#0000bb;">35</span><span style="color:#007700;">,  </span><span style="color:#0000bb;">20</span><span style="color:#007700;">),<br />   array(</span><span style="color:#dd0000;">'2002'</span><span style="color:#007700;">,  </span><span style="color:#0000bb;">65</span><span style="color:#007700;">,  </span><span style="color:#0000bb;">30</span><span style="color:#007700;">,  </span><span style="color:#0000bb;">30</span><span style="color:#007700;">),<br />   array(</span><span style="color:#dd0000;">'2003'</span><span style="color:#007700;">,  </span><span style="color:#0000bb;">70</span><span style="color:#007700;">,  </span><span style="color:#0000bb;">25</span><span style="color:#007700;">,  </span><span style="color:#0000bb;">40</span><span style="color:#007700;">),<br />   array(</span><span style="color:#dd0000;">'2004'</span><span style="color:#007700;">,  </span><span style="color:#0000bb;">72</span><span style="color:#007700;">,  </span><span style="color:#0000bb;">20</span><span style="color:#007700;">,  </span><span style="color:#0000bb;">60</span><span style="color:#007700;">),<br />   array(</span><span style="color:#dd0000;">'2005'</span><span style="color:#007700;">,  </span><span style="color:#0000bb;">75</span><span style="color:#007700;">,  </span><span style="color:#0000bb;">15</span><span style="color:#007700;">,  </span><span style="color:#0000bb;">70</span><span style="color:#007700;">),<br />   array(</span><span style="color:#dd0000;">'2006'</span><span style="color:#007700;">,  </span><span style="color:#0000bb;">77</span><span style="color:#007700;">,  </span><span style="color:#0000bb;">10</span><span style="color:#007700;">,  </span><span style="color:#0000bb;">80</span><span style="color:#007700;">),<br />   array(</span><span style="color:#dd0000;">'2007'</span><span style="color:#007700;">,  </span><span style="color:#0000bb;">80</span><span style="color:#007700;">,   </span><span style="color:#0000bb;">5</span><span style="color:#007700;">,  </span><span style="color:#0000bb;">90</span><span style="color:#007700;">),<br /> );<br /> <br /> </span><span style="color:#ff8000;"># Create a PHPlot object which will make a 600x400 pixel image:<br /> </span><span style="color:#0000bb;">$p </span><span style="color:#007700;">= new </span><span style="color:#0000bb;">PHPlot</span><span style="color:#007700;">(</span><span style="color:#0000bb;">600</span><span style="color:#007700;">, </span><span style="color:#0000bb;">400</span><span style="color:#007700;">);<br /> <br /> </span><span style="color:#ff8000;"># Use TrueType fonts:<br /> </span><span style="color:#0000bb;">$p</span><span style="color:#007700;">-></span><span style="color:#0000bb;">SetDefaultTTFont</span><span style="color:#007700;">(</span><span style="color:#dd0000;">'./arial.ttf'</span><span style="color:#007700;">);<br /> <br /> </span><span style="color:#ff8000;"># Set the main plot title:<br /> </span><span style="color:#0000bb;">$p</span><span style="color:#007700;">-></span><span style="color:#0000bb;">SetTitle</span><span style="color:#007700;">(</span><span style="color:#dd0000;">'PHPlot Customer Satisfaction (estimated)'</span><span style="color:#007700;">);<br /> <br /> </span><span style="color:#ff8000;"># Select the data array representation and store the data:<br /> </span><span style="color:#0000bb;">$p</span><span style="color:#007700;">-></span><span style="color:#0000bb;">SetDataType</span><span style="color:#007700;">(</span><span style="color:#dd0000;">'text-data'</span><span style="color:#007700;">);<br /> </span><span style="color:#0000bb;">$p</span><span style="color:#007700;">-></span><span style="color:#0000bb;">SetDataValues</span><span style="color:#007700;">(</span><span style="color:#0000bb;">$data</span><span style="color:#007700;">);<br /> <br /> </span><span style="color:#ff8000;"># Select the plot type - bar chart:<br /> </span><span style="color:#0000bb;">$p</span><span style="color:#007700;">-></span><span style="color:#0000bb;">SetPlotType</span><span style="color:#007700;">(</span><span style="color:#dd0000;">'bars'</span><span style="color:#007700;">);<br /> <br /> </span><span style="color:#ff8000;"># Define the data range. PHPlot can do this automatically, but not as well.<br /> </span><span style="color:#0000bb;">$p</span><span style="color:#007700;">-></span><span style="color:#0000bb;">SetPlotAreaWorld</span><span style="color:#007700;">(</span><span style="color:#007700;">, </span><span style="color:#007700;">, </span><span style="color:#0000bb;">7</span><span style="color:#007700;">, </span><span style="color:#0000bb;">100</span><span style="color:#007700;">);<br /> <br /> </span><span style="color:#ff8000;"># Select an overall image background color and another color under the plot:<br /> </span><span style="color:#0000bb;">$p</span><span style="color:#007700;">-></span><span style="color:#0000bb;">SetBackgroundColor</span><span style="color:#007700;">(</span><span style="color:#dd0000;">'#ffffcc'</span><span style="color:#007700;">);<br /> </span><span style="color:#0000bb;">$p</span><span style="color:#007700;">-></span><span style="color:#0000bb;">SetDrawPlotAreaBackground</span><span style="color:#007700;">(</span><span style="color:#0000bb;">True</span><span style="color:#007700;">);<br /> </span><span style="color:#0000bb;">$p</span><span style="color:#007700;">-></span><span style="color:#0000bb;">SetPlotBgColor</span><span style="color:#007700;">(</span><span style="color:#dd0000;">'#ffffff'</span><span style="color:#007700;">);<br /> <br /> </span><span style="color:#ff8000;"># Draw lines on all 4 sides of the plot:<br /> </span><span style="color:#0000bb;">$p</span><span style="color:#007700;">-></span><span style="color:#0000bb;">SetPlotBorderType</span><span style="color:#007700;">(</span><span style="color:#dd0000;">'full'</span><span style="color:#007700;">);<br /> <br /> </span><span style="color:#ff8000;"># Set a 3 line legend, and position it in the upper left corner:<br /> </span><span style="color:#0000bb;">$p</span><span style="color:#007700;">-></span><span style="color:#0000bb;">SetLegend</span><span style="color:#007700;">(array(</span><span style="color:#dd0000;">'Features'</span><span style="color:#007700;">, </span><span style="color:#dd0000;">'Bugs'</span><span style="color:#007700;">, </span><span style="color:#dd0000;">'Happy Users'</span><span style="color:#007700;">));<br /> </span><span style="color:#0000bb;">$p</span><span style="color:#007700;">-></span><span style="color:#0000bb;">SetLegendWorld</span><span style="color:#007700;">(</span><span style="color:#0000bb;">0.1</span><span style="color:#007700;">, </span><span style="color:#0000bb;">95</span><span style="color:#007700;">);<br /> <br /> </span><span style="color:#ff8000;"># Turn data labels on, and all ticks and tick labels off:<br /> </span><span style="color:#0000bb;">$p</span><span style="color:#007700;">-></span><span style="color:#0000bb;">SetXDataLabelPos</span><span style="color:#007700;">(</span><span style="color:#dd0000;">'plotdown'</span><span style="color:#007700;">);<br /> </span><span style="color:#0000bb;">$p</span><span style="color:#007700;">-></span><span style="color:#0000bb;">SetXTickPos</span><span style="color:#007700;">(</span><span style="color:#dd0000;">'none'</span><span style="color:#007700;">);<br /> </span><span style="color:#0000bb;">$p</span><span style="color:#007700;">-></span><span style="color:#0000bb;">SetXTickLabelPos</span><span style="color:#007700;">(</span><span style="color:#dd0000;">'none'</span><span style="color:#007700;">);<br /> </span><span style="color:#0000bb;">$p</span><span style="color:#007700;">-></span><span style="color:#0000bb;">SetYTickPos</span><span style="color:#007700;">(</span><span style="color:#dd0000;">'none'</span><span style="color:#007700;">);<br /> </span><span style="color:#0000bb;">$p</span><span style="color:#007700;">-></span><span style="color:#0000bb;">SetYTickLabelPos</span><span style="color:#007700;">(</span><span style="color:#dd0000;">'none'</span><span style="color:#007700;">);<br /> <br /> </span><span style="color:#ff8000;"># Generate and output the graph now:<br /> </span><span style="color:#0000bb;">$p</span><span style="color:#007700;">-></span><span style="color:#0000bb;">DrawGraph</span><span style="color:#007700;">();</span></span></code></p>    <p><br /> PHPlot 5.6.0 发布了,该版本改进了饼图,提供新选项用于标签内容和格式化,新增用于更改图表大小的方法,完善了文档,提供了新的例子。</p>    <p><img style="width:572px;height:381px;" alt="PHP图表制作库,PHPlot 5.6.0 发布," src="https://simg.open-open.com/show/cc4b895d52ae382cebce903b62811386.png" /></p>