- 论坛徽章:
- 0
|
<?php
require_once 'phplot.php';
//设置数据
$data = array(
array('2010', 10, 2),
array('2011', 15, ,
array('2012', 20, 14),
array('2013', 25, 24),
array('2014', 30, 35),
array('2015', 35, 45),
array('2016', 40, 60)
);
$p = new PHPlot(600, 300);
$p->SetDefaultTTFont('Fonts/simhei.ttf'); //设置字体,还是支持中文的吧
$p->SetTitle(iconv_arr('Phpwind疾风学院男女人数比例')); //设置标题,还是用iconv_arr来解决中文
# Select the data array representation and store the data:
$p->SetDataType('text-data'); //设置使用的数据类型,在这个里面可以使用多种类型。
$p->SetDataValues($data); //把一个数组$data赋给类的一个变量$this->data_values.要开始作图之前调用。
$p->SetPlotType('lines'); //选择图表类型为线性.可以是bars,lines,linepoints,area,points,pie等。
$p->SetPlotAreaWorld(0, 0, 7, 100); //设置图表边距
# Select an overall image background color and another color under the plot:
$p->SetBackgroundColor('#ffffcc'); //设置整个图象的背景颜色。
$p->SetDrawPlotAreaBackground(True); //设置节点区域的背景
$p->SetPlotBgColor('#ffffff'); //设置使用SetPlotAreaPixels()函数设定的区域的颜色。
$p->SetLineWidth(3); //线条宽度
# Draw lines on all 4 sides of the plot:
$p->SetPlotBorderType('full'); //设置线条类型
# Set a 3 line legend, and position it in the upper left corner:
$p->SetLegend(iconv_arr(array('男生人数', '女生人数'))); //显示在一个图列框中的说明
$p->SetLegendWorld(0.3, 95); //设定这个文本框位置
# Generate and output the graph now:
$p->DrawGraph();
function iconv_arr($data){
if(is_array($data)){
foreach($data as $k=>$v){
$data[$k] = iconv_arr($v);
}
}else{
$data = mb_convert_encoding($data, "html-entities","gbk" );
}
return $data;
} |
|