Home php教程 php手册 php报表之jpgraph柱状图实例代码

php报表之jpgraph柱状图实例代码

Jun 06, 2016 pm 08:38 PM
jpgraph bar chart

jpgraph是php中一个非常非常强大的第三方报表工具,据说能完成一切你想要的图形

新手初识jpgraph肯定会遇到各种各样的问题,比如乱码什么的,本案例是jpgraph3.0.7制作,也经过本人的多次实验,解决乱码问题
代码如下:
$datay=array(); //纵坐标数据
$datax=array(); //横坐标数据
foreach ($usernums as $key => $value){
$datay[] = $value;
$datax[] = $userids[$key];
}
require_once (‘jpgraph-3.0.7/jpgraph/jpgraph.php');
require_once (‘jpgraph-3.0.7/jpgraph/jpgraph_bar.php');
// Create the graph. These two calls are always required
$graph = new Graph(800,600); //图像高宽
$graph->SetScale(“textlin”);
$graph->xaxis->SetTickLabels($datax);
$graph->xaxis->SetFont(FF_VERDANA,FS_NORMAL,10);
$graph->xaxis->SetLabelAngle(30);
$graph->yaxis->scale->SetGrace(20);
$graph->xaxis->scale->SetGrace(20);
// Add a drop shadow
$graph->SetShadow();
// Adjust the margin a bit to make more room for titles
$graph->img->SetMargin(40,30,20,40);
// Create a bar pot
$bplot = new BarPlot($datay);
// Adjust fill color
$bplot->SetFillColor(‘orange');
$bplot->value->Show();
$bplot->value->SetFont(FF_ARIAL,FS_BOLD,10);
$bplot->value->SetAngle(45);
$bplot->value->SetFormat(‘%d');
$graph->Add($bplot);
// Setup the titles
$graph->title->Set(iconv(“UTF-8″, “gb2312″,”用户消费报表图”));
$graph->xaxis->title->Set(iconv(“UTF-8″, “gb2312″,”用户姓名”));
$graph->yaxis->title->Set(iconv(“UTF-8″, “gb2312″,”用户订单数量”));
$graph->xaxis->title->SetFont(FF_SIMSUN,FS_BOLD);
$graph->yaxis->title->SetFont(FF_SIMSUN,FS_BOLD);
$graph->title->SetFont(FF_SIMSUN,FS_BOLD);
// Display the graph
$graph->Stroke();
?>


官方网站 脚本之家下载地址

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot Article Tags

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

How to make a histogram in WPS documents How to make a histogram in WPS documents Mar 20, 2024 pm 10:11 PM

How to make a histogram in WPS documents

Data visualization techniques such as bar charts and pie charts in Vue Data visualization techniques such as bar charts and pie charts in Vue Jun 25, 2023 pm 12:43 PM

Data visualization techniques such as bar charts and pie charts in Vue

Use PHP and JpGraph to generate and draw charts Use PHP and JpGraph to generate and draw charts Jun 25, 2023 pm 06:16 PM

Use PHP and JpGraph to generate and draw charts

How to generate histogram using ECharts and Python interface How to generate histogram using ECharts and Python interface Dec 17, 2023 pm 01:54 PM

How to generate histogram using ECharts and Python interface

Implementation of column and line chart functions in Vue statistical charts Implementation of column and line chart functions in Vue statistical charts Aug 17, 2023 am 11:39 AM

Implementation of column and line chart functions in Vue statistical charts

Learn to draw line charts, bar charts and pie charts with Python in three minutes Learn to draw line charts, bar charts and pie charts with Python in three minutes Sep 27, 2023 am 09:29 AM

Learn to draw line charts, bar charts and pie charts with Python in three minutes

How to use histogram to display data in ECharts How to use histogram to display data in ECharts Dec 18, 2023 pm 02:21 PM

How to use histogram to display data in ECharts

Python program to draw histogram using turtle Python program to draw histogram using turtle Aug 20, 2023 pm 04:57 PM

Python program to draw histogram using turtle

See all articles