例如最简单的柱状图生成:、
require '/path/to/your/vendor/autoload.php';
use CpChart\Data;
use CpChart\Image;
/* 创建并设置图表数据对象 */
$data = new Data();
$data->addPoints([13251, 4118, 3087, 1460, 1248, 156, 26, 9, 8], "Hits");
$data->setAxisName(0, "Hits");
$data->addPoints(["Firefox", "Chrome", "Internet Explorer", "Opera", "Safari", "Mozilla", "SeaMonkey", "Camino", "Lunascape"], "Browsers");
$data->setSerieDescription("Browsers", "Browsers");
$data->setAbscissa("Browsers");
/* 创建并设置图片对象 */
$image = new Image(500, 500, $data);
$image->drawGradientArea(0, 0, 500, 500, DIRECTION_VERTICAL, ["StartR" => 240, "StartG" => 240, "StartB" => 240, "EndR" => 180, "EndG" => 180, "EndB" => 180, "Alpha" => 100]);
$image->drawGradientArea(0, 0, 500, 500, DIRECTION_HORIZONTAL, ["StartR" => 240, "StartG" => 240, "StartB" => 240, "EndR" => 180, "EndG" => 180, "EndB" => 180, "Alpha" => 20]);
$image->setFontProperties(["FontName" => "pf_arma_five.ttf", "FontSize" => 6]);
/* 绘制柱状图坐标 */
$image->setGraphArea(100, 30, 480, 480);
$image->drawScale(["CycleBackground" => true, "DrawSubTicks" => true, "GridR" => 0, "GridG" => 0, "GridB" => 0, "GridAlpha" => 10, "Pos" => SCALE_POS_TOPBOTTOM]);
/* 绘制阴影 */
$image->setShadow(true, ["X" => 1, "Y" => 1, "R" => 0, "G" => 0, "B" => 0, "Alpha" => 10]);
/* 绘制柱 */
$image->drawBarChart(["DisplayPos" => LABEL_POS_INSIDE, "DisplayValues" => true, "Rounded" => true, "Surrounding" => 30]);
/* 绘制小色块(柱状图旁边的带名称小色块,用于区分不同颜色) */
$image->drawLegend(570, 215, ["Style" => LEGEND_NOBORDER, "Mode" => LEGEND_HORIZONTAL]);
/* 导出图表 */
$image->autoOutput("example.drawBarChart.vertical.png");