统计图表类库--libchart使用简介

1.饼图

#载入类文件
include "../libchart/classes/libchart.php";
header("Content-type: image/png");
$chart = new PieChart(500, 300);
$dataSet = new XYDataSet();
#添加数据
$dataSet->addPoint(new Point("Bleu d'Auvergne", 50));
$dataSet->addPoint(new Point("Tomme de Savoie", 75));
$dataSet->addPoint(new Point("Crottin de Chavignol", 30));
#设置图表信息
$chart->setDataSet($dataSet);
$chart->setTitle("Preferred Cheese");
#输出图表
$chart->render();

2.横向柱形图

#载入类文件
include "../libchart/classes/libchart.php";
$chart = new HorizontalBarChart(600, 170);
$dataSet = new XYDataSet();
#添加数据
$dataSet->addPoint(new Point("/wiki/Instant_messenger", 50));
$dataSet->addPoint(new Point("/wiki/Web_Browser", 75));
$dataSet->addPoint(new Point("/wiki/World_Wide_Web", 122));
#设置并输出
$chart->setDataSet($dataSet);
$chart->getPlot()->setGraphPadding(new Padding(5, 30, 20, 140));
$chart->setTitle("Most visited pages for www.example.com");
$chart->render();

Horizontal bars chart

3.纵向柱形图

#载入类文件
include "../libchart/classes/libchart.php";
$chart = new VerticalBarChart();
$dataSet = new XYDataSet();
#添加数据
$dataSet->addPoint(new Point("Jan 2005", 273));
$dataSet->addPoint(new Point("Feb 2005", 421));
$dataSet->addPoint(new Point("March 2005", 642));
$dataSet->addPoint(new Point("April 2005", 800));
$dataSet->addPoint(new Point("May 2005", 1200));
$dataSet->addPoint(new Point("June 2005", 1500));
$dataSet->addPoint(new Point("July 2005", 2600));
#设置并输出
$chart->setDataSet($dataSet);
$chart->setTitle("Monthly usage for www.example.com");
$chart->render();

Vertical bars chart

4.折线图

#载入类文件
include "../libchart/classes/libchart.php";
$chart = new LineChart();
$dataSet = new XYDataSet();
#添加数据
$dataSet->addPoint(new Point("06-01", 273));
$dataSet->addPoint(new Point("06-02", 421));
$dataSet->addPoint(new Point("06-03", 642));
$dataSet->addPoint(new Point("06-04", 799));
$dataSet->addPoint(new Point("06-05", 1009));
$dataSet->addPoint(new Point("06-06", 1406));
$dataSet->addPoint(new Point("06-07", 1820));
$dataSet->addPoint(new Point("06-08", 2511));
$dataSet->addPoint(new Point("06-09", 2832));
$dataSet->addPoint(new Point("06-10", 3550));
$dataSet->addPoint(new Point("06-11", 4143));
$dataSet->addPoint(new Point("06-12", 4715));
#设置并输出
$chart->setDataSet($dataSet);
$chart->setTitle("Sales for 2006");
$chart->render();

Line chart

转载于:https://www.cnblogs.com/boystar/p/4692320.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值