Home php教程 php手册 jpgraph+php+mysql生成柱状图(含附件)

jpgraph+php+mysql生成柱状图(含附件)

Jun 21, 2016 am 08:51 AM
graph gt quot

  很详细的注释,希望对像我一样刚入门的朋友有帮助,附代码:

  CREATE DATABASE `jpgraph`; //创建数据库

  USE `jpgraph`;

  //创建测试表

  DROP TABLE IF EXISTS `jpg_temp`;

  CREATE TABLE `jpg_temp` (

  `year` int(11) NOT NULL,

  `money` float NOT NULL,

  `number` int(11) NOT NULL

  ) ENGINE=InnoDB DEFAULT CHARSET=latin1;

  //测试数据

  insert into `jpg_temp`(`year`,`money`,`number`) values (2007,150.78,120),(2008,100,90),(2009,120,100),(2010,100,78),(2011,70.56,60),(2012,90,100),(2013,140,180),(2014,150,200),(2015,130,110),(2016,110.85,150),(2020,180,230),(2050,200,210);

  //数据库链接文件

  

  /*

  * ProjectName:jpgraph

  * CreateDate:2011-5-12

  * Author:Wilr

  * Description:数据库链接

  */

  $dbConn=mysql_connect("127.0.0.1","root","root");

  if(!$dbConn)

  echo '数据库通信失败';

  mysql_select_db("jpgraph");

  mysql_query("set names 'utf8'",$dbConn);

  $sql= " SELECT * FROM jpg_temp";

  $result=mysql_query($sql,$dbConn);

  $rowCount=mysql_num_rows($result);

  $datay=array();

  $datax=array();

  $number=array();

  while ($row=mysql_fetch_array($result)){

  $datay[]=$row["money"];

  $datax[]=$row["year"];

  $number[]=$row["number"];

  }

  //echo each($datay);

  //print_r($datay);

  mysql_close($dbConn);

  ?>

  //生成图表类

  

  require_once ('jpgraph/jpgraph.php'); //载入基本类

  require_once ('jpgraph/jpgraph_bar.php'); //载入柱状图

  include_once('db_config.php'); //载入数据处理文件

  $graph=new Graph(900,500); //创建一个图表 指定大小

  $graph->SetScale("textlin"); //设置坐标刻度类型

  $graph->img->SetMargin(40,180,30,40);//设置统计图边距 左、右、上、下

  //$graph->SetMarginColor("lightblue");//设置画布背景色 淡蓝色

  //$graph->SetBackgroundImage('stship.jpg',BGIMG_COPY); //设置背景图片

  //$graph->img->SetAngle(45); //设置图形在图像中的角度

  //设置标题信息

  $graph->title->Set('Wilr测试报表'); //设置统计图标题

  $graph->title->SetFont(FF_SIMSUN,FS_BOLD,20); //设置标题字体

  $graph->title->SetMargin(3);//设置标题的边距

  //设置X轴信息

  $graph->xaxis->title->Set('(单位:年)'); //标题

  $graph->xaxis->title->SetFont(FF_SIMSUN,FS_BOLD,10); //标题字体 大小

  $graph->xaxis->title->SetColor('black');//颜色

  $graph->xaxis->SetFont(FF_SIMSUN,FS_BOLD,10);//X轴刻度字体 大小

  $graph->xaxis->SetColor('black');//X轴刻度颜色

  $graph->xaxis->SetTickLabels($datax); //设置X轴标记

  $graph->xaxis->SetLabelAngle(0);//设置X轴的显示值的角度;

  //设置Y轴的信息

  $graph->yaxis->SetFont(FF_SIMSUN,FS_BOLD,10);//标题

  $graph->yaxis->SetColor('black');//颜色

  $graph->ygrid->SetColor('black@0.9');//X,y交叉表格颜色和透明度 @为程度值

  $graph->yaxis->scale->SetGrace(0);//设置Y轴显示值柔韧度(解释有点问题 呵呵 原谅)

  //设置数据

  $bplot1 = new BarPlot($datay);

  $bplot2 = new BarPlot($number);

  //设置柱状图柱颜色和透明度

  $bplot1->SetFillColor('orange@0.4');

  $bplot2->SetFillColor('brown@0.4');

  //设置值显示

  $bplot1->value->Show(); //显示值

  $bplot1->value->SetFont(FF_SIMSUN,FS_BOLD,10);//显示字体大小

  $bplot1->value->SetAngle(90); //显示角度

  $bplot1->value->SetFormat('%0.2f'); //显示格式 0.2f:精确到小属数点后2位

  $bplot2->value->Show();

  $bplot2->value->SetFont(FF_SIMSUN,FS_BOLD,10);

  $bplot2->value->SetAngle(90);

  $bplot2->value->SetFormat('%0.0f');

  //设置图列标签

  $graph->legend->SetFillColor('lightblue@0.9');//设置图列标签背景颜色和透明度

  $graph->legend->Pos(0.01,0.12,"right","center");//位置

  $graph->legend->SetFont(FF_SIMSUN,FS_NORMAL,10);//显示字体 大小

  $bplot1->SetLegend('消费金额(单位:万元)');

  $bplot2->SetLegend('人数(单位:万人次)');

  //设置每个柱状图的颜色和阴影透明度

  $bplot1->SetShadow('black@0.4');

  $bplot2->SetShadow('black@0.4');

  //生成图列

  $gbarplot = new GroupBarPlot(array($bplot1,$bplot2));

  $gbarplot->SetWidth(0.5); //柱状的宽度

  $graph->Add($gbarplot);

  $graph->Stroke(); //输出图像

  ?>

 

附件:  效果图.zip (25 K) 



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 AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

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)

What are the differences between Huawei GT3 Pro and GT4? What are the differences between Huawei GT3 Pro and GT4? Dec 29, 2023 pm 02:27 PM

Many users will choose the Huawei brand when choosing smart watches. Among them, Huawei GT3pro and GT4 are very popular choices. Many users are curious about the difference between Huawei GT3pro and GT4. Let’s introduce the two to you. . What are the differences between Huawei GT3pro and GT4? 1. Appearance GT4: 46mm and 41mm, the material is glass mirror + stainless steel body + high-resolution fiber back shell. GT3pro: 46.6mm and 42.9mm, the material is sapphire glass + titanium body/ceramic body + ceramic back shell 2. Healthy GT4: Using the latest Huawei Truseen5.5+ algorithm, the results will be more accurate. GT3pro: Added ECG electrocardiogram and blood vessel and safety

Fix: Snipping tool not working in Windows 11 Fix: Snipping tool not working in Windows 11 Aug 24, 2023 am 09:48 AM

Why Snipping Tool Not Working on Windows 11 Understanding the root cause of the problem can help find the right solution. Here are the top reasons why the Snipping Tool might not be working properly: Focus Assistant is On: This prevents the Snipping Tool from opening. Corrupted application: If the snipping tool crashes on launch, it might be corrupted. Outdated graphics drivers: Incompatible drivers may interfere with the snipping tool. Interference from other applications: Other running applications may conflict with the Snipping Tool. Certificate has expired: An error during the upgrade process may cause this issu simple solution. These are suitable for most users and do not require any special technical knowledge. 1. Update Windows and Microsoft Store apps

How to Fix Can't Connect to App Store Error on iPhone How to Fix Can't Connect to App Store Error on iPhone Jul 29, 2023 am 08:22 AM

Part 1: Initial Troubleshooting Steps Checking Apple’s System Status: Before delving into complex solutions, let’s start with the basics. The problem may not lie with your device; Apple's servers may be down. Visit Apple's System Status page to see if the AppStore is working properly. If there's a problem, all you can do is wait for Apple to fix it. Check your internet connection: Make sure you have a stable internet connection as the "Unable to connect to AppStore" issue can sometimes be attributed to a poor connection. Try switching between Wi-Fi and mobile data or resetting network settings (General > Reset > Reset Network Settings > Settings). Update your iOS version:

php提交表单通过后,弹出的对话框怎样在当前页弹出,该如何解决 php提交表单通过后,弹出的对话框怎样在当前页弹出,该如何解决 Jun 13, 2016 am 10:23 AM

php提交表单通过后,弹出的对话框怎样在当前页弹出php提交表单通过后,弹出的对话框怎样在当前页弹出而不是在空白页弹出?想实现这样的效果:而不是空白页弹出:------解决方案--------------------如果你的验证用PHP在后端,那么就用Ajax;仅供参考:HTML code

Steps to use Python to manipulate Ethereum Graph data Steps to use Python to manipulate Ethereum Graph data May 08, 2023 am 10:01 AM

Before we get started, let's look at some definitions. GraphQL is a query language TheGraph is a blockchain project using the GraphQL query language. The project allows anyone to build and publish an open API called subgraph. The Graph project uses GraphQL, a syntax that describes how to interrogate data. This syntax is not tied to a specific type of database or storage engine, but is supported by your existing code and data. GraphQL Let's start by looking at a very simple GraphQL query structure and the results we get when we run it. Once the GraphQL service is running, it can receive GraphQL queries

Is watch4pro better or gt? Is watch4pro better or gt? Sep 26, 2023 pm 02:45 PM

Watch4pro and gt each have different features and applicable scenarios. If you focus on comprehensive functions, high performance and stylish appearance, and are willing to bear a higher price, then Watch 4 Pro may be more suitable. If you don’t have high functional requirements and pay more attention to battery life and reasonable price, then the GT series may be more suitable. The final choice should be decided based on personal needs, budget and preferences. It is recommended to carefully consider your own needs before purchasing and refer to the reviews and comparisons of various products to make a more informed choice.

How to optimize iPad battery life with iPadOS 17.4 How to optimize iPad battery life with iPadOS 17.4 Mar 21, 2024 pm 10:31 PM

How to Optimize iPad Battery Life with iPadOS 17.4 Extending battery life is key to the mobile device experience, and the iPad is a good example. If you feel like your iPad's battery is draining too quickly, don't worry, there are a number of tricks and tweaks in iPadOS 17.4 that can significantly extend the run time of your device. The goal of this in-depth guide is not just to provide information, but to change the way you use your iPad, enhance your overall battery management, and ensure you can rely on your device for longer without having to charge it. By adopting the practices outlined here, you take a step toward more efficient and mindful use of technology that is tailored to your individual needs and usage patterns. Identify major energy consumers

请教怎么修改url某一参数的参数值呢?是要拆开了再拼回去吗 请教怎么修改url某一参数的参数值呢?是要拆开了再拼回去吗 Jun 13, 2016 am 10:24 AM

请问如何修改url某一参数的参数值呢?是要拆开了再拼回去吗?那么请问如何修改url某一参数的参数值呢?是要拆开了再拼回去吗?http://127.0.0.1/myo/newuser.php?mod=search&type=fastone比如现在我要修改mod=new要怎么做呢?------解决方案--------------------发送了请求

See all articles