Use of the plug-in highcharts in thinkphp
[1] Introduction
(1) Introduction
Highcharts is a foreign icon plug-in and statistical chart developed based on jquery. Line charts, pie charts, etc. are often used.
There is also a similar plug-in echarts in China, developed by Baidu.
(2) Support special effects demo: 3D, dashboard, discount, ECG-like real-time refresh, columnar, dotted, radar, funnel, pyramid
Funnel chart: commonly used for sales trends, The top ones are interested users, and the bottom ones are transaction customers. Specifically, there are the following categories
(3) Application examples: QQ’s national online population distribution, done through Flash; Baidu echarts’ national data distribution, done through js
is very intuitively reflected Internet development situation and regions in China. The more bright spots, the more developed the local Internet is. Developed areas include Beijing, Shanghai, Guangzhou, and Chongqing
(4) echarts contains richer demos and has been expanded a lot, including global routes and stock data trends
(5) The usage is basically the same
[2] Case
Use Highcharts to implement department head count
Requirement: Use icon form to count the number of people in each department
(1) Preparation and steps:
1. Select the style directory, here I use examples/column-rotated-labels
;
2. Analyze the demo: ①Introduce jquery and js Class file; ② Replace data data; ③ Declare div icon container to place icons
(2) Start writing
1. Modify the template file User/showList.html and add the following statistics Click the button to set the link and jump to the statistics page
There is no need to do anything here, so just modify the href of the a tag directly. What should be written? It depends on the method
2. Define the icon page method charts. The method is written in the User controller, so the href is written as __CONTROLLER__/charts
3. Define the charts method to display the chart template File
//charts图表 public function charts(){ $this->display(); }
4. Copy the template file to the specified location; at the same time, in order to access the website faster online, you need to copy the static resource file to the site directory;
①Here is copied to User/charts , under html;
②Introduce static resources and modify the path: For convenience, I directly copied the entire code to the static resource directory, and the plug-ins used later are placed in the plugin directory
5. Rewrite the chars method, query the data, and replace the data in the template file
First analyze the final data format: Product Department: 10, Technology Department 20, Ministry of Foreign Affairs 30.... .
This cannot be achieved with just one data table, so joint table query is required(sp_user, sp_dept)
Main tablesp_user(t1)
;From Tablesp_dept(t2)
;
Association conditions: t1.dept_id = t2.id
Native SQL statement table method:
select t2.name as deptname,count(*) as count from sp_user as t1,sp_dept as t2 where t1.dept_id=t2.id group by deptname;
The output is correct after running in Navicat, so the next
TP coherent operation:
public function charts(){ $model = M(); //连贯操作 $data = $model->field('t2.name as deptname,count(*) as count')->table('sp_user as t1,sp_dept as t2') ->where('t1.dept_id=t2.id')->group('deptname')->select(); dump($data);die; $this->display(); }
Output $data result:
array(3) { [0] => array(2) { ["deptname"] => string(9) "人力部" ["count"] => string(1) "3" } [1] => array(2) { ["deptname"] => string(9) "技术部" ["count"] => string(1) "2" } [2] => array(2) { ["deptname"] => string(9) "财务部" ["count"] => string(1) "3" } }
If the current ThinkPHP version is 5.6, you can directly assign the data two-dimensional array without any processing. Versions below 5.6 require string splicing
$str = "[";//循环遍历字符串 foreach ($data as $key => $value) { $str .= "['".$value['deptname']."',".$value['count']."],"; } //去除最后的, $str = rtrim($str,','); $str .= "]";
6. Pass variables to the template;
7. Modify the template and receive variables. Delete the original array and pass variables instead
data:{$str},
(3) Improve the details
1. Modify the header
2. Modify the unit information on the left
3. Modify the mouse hover effect (as of now)
4. Modify the decimal point on the icon (change 1f to 0f, meaning accurate to 0 digits);
5. As for the operation of printing pictures, you need to modify highcharts.js, just modify it from the source code. Query and enter relevant words and modify them
Summary:
(1).1f means accurate to 1 decimal place (such as 3.0, 5.0), if you don’t want it. 0, it can be accurate to 0 decimal places (such as 3, 5)
The above is the entire content of ThinkPHP---plug-in highcharts.
Related references:thinkphp tutorial
The above is the detailed content of Use of the plug-in highcharts in thinkphp. For more information, please follow other related articles on the PHP Chinese website!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

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

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics



To run the ThinkPHP project, you need to: install Composer; use Composer to create the project; enter the project directory and execute php bin/console serve; visit http://localhost:8000 to view the welcome page.

ThinkPHP has multiple versions designed for different PHP versions. Major versions include 3.2, 5.0, 5.1, and 6.0, while minor versions are used to fix bugs and provide new features. The latest stable version is ThinkPHP 6.0.16. When choosing a version, consider the PHP version, feature requirements, and community support. It is recommended to use the latest stable version for best performance and support.

Steps to run ThinkPHP Framework locally: Download and unzip ThinkPHP Framework to a local directory. Create a virtual host (optional) pointing to the ThinkPHP root directory. Configure database connection parameters. Start the web server. Initialize the ThinkPHP application. Access the ThinkPHP application URL and run it.

"Development Suggestions: How to Use the ThinkPHP Framework to Implement Asynchronous Tasks" With the rapid development of Internet technology, Web applications have increasingly higher requirements for handling a large number of concurrent requests and complex business logic. In order to improve system performance and user experience, developers often consider using asynchronous tasks to perform some time-consuming operations, such as sending emails, processing file uploads, generating reports, etc. In the field of PHP, the ThinkPHP framework, as a popular development framework, provides some convenient ways to implement asynchronous tasks.

Performance comparison of Laravel and ThinkPHP frameworks: ThinkPHP generally performs better than Laravel, focusing on optimization and caching. Laravel performs well, but for complex applications, ThinkPHP may be a better fit.

ThinkPHP installation steps: Prepare PHP, Composer, and MySQL environments. Create projects using Composer. Install the ThinkPHP framework and dependencies. Configure database connection. Generate application code. Launch the application and visit http://localhost:8000.

ThinkPHP is a high-performance PHP framework with advantages such as caching mechanism, code optimization, parallel processing and database optimization. Official performance tests show that it can handle more than 10,000 requests per second and is widely used in large-scale websites and enterprise systems such as JD.com and Ctrip in actual applications.

Development suggestions: How to use the ThinkPHP framework for API development. With the continuous development of the Internet, the importance of API (Application Programming Interface) has become increasingly prominent. API is a bridge for communication between different applications. It can realize data sharing, function calling and other operations, and provides developers with a relatively simple and fast development method. As an excellent PHP development framework, the ThinkPHP framework is efficient, scalable and easy to use.
