项目地址: https://github.com/bozhinov/pChart2.0-for-PHP7
thinkphp + pChar 使用视频: https://www.bilibili.com/video/av78285655
离线
离线
pChart自带了字体文件, 但是那个字体不支持中文, 代码里面要重设一个中文字库,不过要注意字库版权,比如微软雅黑版权属于方正的,用于图片估计不合规。
离线
/* 极地和雷达图 */
//引入 pChart 库
include("../class/pData.class.php");
include("../class/pDraw.class.php");
include("../class/pRadar.class.php");
include("../class/pImage.class.php");
//图像大小
$width = 500;
$height = 500;
//绘制位置
$x = 100;
$y = 100;
//分数
$scores = array(
"身份特质"=>5,
"履约能力"=>4,
"信用历史"=>5.5,
"人脉关系"=>4,
"行为偏好"=>3.5
);
//创建并赋值 pData 对象
$MyData = new pData();
$MyData->addPoints(array_values($scores), "Score");
$MyData->setSerieDescription("Score", "Application A");
$MyData->setPalette("Score", array("R" => 0, "G" => 180, "B" => 138));
//定义 absissa
$MyData->addPoints(array_keys($scores), "Labels");
$MyData->setAbscissa("Labels", array("R" => 10, "G" => 170, "B" => 133));
//创建 pChart 对象
$myPicture = new pImage($width, $height, $MyData);
//设置默认字体属性(这里我使用开源的字体:思源黑体)
$myPicture->setFontProperties(array("FontName" => "../fonts/SOURCEHANSANSCN-MEDIUM.OTF", "FontSize" => 10, "R" => 80, "G" => 80, "B" => 80));
//创建 pRadar 对象
$SplitChart = new pRadar();
//绘制雷达图
$myPicture->setGraphArea($x, $y, $width-$x, $height-$y); //设置雷达图区域位开始位置和结束位置
$Options = array(
"Layout" => RADAR_LAYOUT_STAR, //雷达布局 RADAR_LAYOUT_STAR=>尖角雷达图,RADAR_LAYOUT_CIRCLE=>圆角雷达图
"LabelPos" => RADAR_LABELS_HORIZONTAL, //类型标签 RADAR_LABELS_HORIZONTAL=>水平,RADAR_LABELS_ROTATED=>旋转
"BackgroundGradient" => array( //背景梯度渐变
"StartR" => 246,
"StartG" => 246,
"StartB" => 246,
"StartAlpha" => 100,
"EndR" => 246,
"EndG" => 246,
"EndB" => 246,
"EndAlpha" => 100
),
'AxisR' => 225,
'AxisG' => 225,
'AxisB' => 225,
'AxisAlpha' => 100,
'AxisRotation' => -90, //旋转轴(角度)
'DrawAxisValues' => false, //画坐标轴的值
'DrawPoly' => true, //区域阴影
"ValueFontSize" => 8, //在坐标轴顶点标注数值字体大小
'WriteValues' => false, //在坐标轴顶点标注数值
'WriteValuesInBubble' => false, //在顶点气泡中标注
'ValuePadding' => 0, //在顶点气泡中标注大小
'OuterBubbleRadius' => 0, //顶点气泡颜色
'DrawPoints' => false, //画坐标顶点的小圆点
'PointRadius' => 5, //坐标顶点的小圆点大小
'DrawLines' => true, //画坐标点连接线(首尾点不连接 适用于xy坐标轴)
'LineLoopStart' => true, //链接首尾的点
'SegmentHeight' => 2, //设置每个坐标格大小
'Segments' => 3, //设置雷达图显示几个坐标格
);
$SplitChart->drawRadar($myPicture, $MyData, $Options);
//渲染图片(选择最佳方式)
$myPicture->autoOutput("pictures/example.radar.values.png");
离线