PHP-based ultra-cool HTML5 interactive charts. PHP-based ultra-cool HTML5 interactive charts use PHP to implement professional-level Web-based charts without in-depth HTML5 and JavaScript knowledge. Introduction recently, I need to quickly develop PHP-based ultra-cool HTML5 interactive charts from a group of PHP Data groups
Use PHP to implement professional-level Web-based charts without in-depth HTML5 and JavaScript knowledge.
Introduction
Recently, I need to quickly create charts from a group of PHP Data groups. The required charts must be interactive, user-friendly, and downloadable. After evaluating some PHP chart solutions, including phpChart, pChart, and Highcharts, I decided to use phpChart as my preferred tool.
Background
As a major backend programmer, I don't have much time to study using JavaScript to see charts online within 24 hours.) I don't have any advanced front-end coding knowledge. Basically, I want PHP developers who have almost no front-end programming experience to quickly develop exquisite charts.
I tried pChart, a popular PHP chart Library. The generated chart looks pretty good. although it can be downloaded, it is still a static image. Highcharts seems to be the best choice. A chart looks amazing, it is animated, and has many custom options, but it is also very complicated and requires a lot of JavaScript knowledge. Highcharts is neither designed for PHP nor free for business purposes.
Basic elements of phpChart
What I like most about phpChart is that it allows people to start with simple and minimal code.
PhpChart Lite version can be downloaded from http: // phpchArt.org/downLoads /. Download the file and decompress it to the root directory of the website.
Set conf. php
The first thing we need to do is set variables.SCRIPTPATHTo the PhpChart class library in the conf. php file. This variable represents the relative or absolute URL of the phpChart library on your Web server.
- define('SCRIPTPATH','/phpChart/');
Create the simplest chart
- Include the PHP header file conf. php:
- Require_once ("../conf. php ");
Call constructorC_PhpChartXAnd call the draw () function.
- $pc=new C_PhpChartX(array(array(123, 34, 51, 22, 3)), ‘simplest_graph’);
- $pc->draw();
This is the code you need. The following figure shows the rendered output.
This is what I call the minimum number of codes. When you have a team of programmers to work, it doesn't make sense to study the basics. One thing that any programmer wants to do as soon as possible is to study complex documents from a new set of libraries or tools.
By the way, the name of the second parameter in the constructor should be unique for your chart. I typed "simplest_graph" or any non-space string. It must be a unique value so that you can have multiple charts on a page.
Add title
You should add titles for your charts so that users can know what they are watching.
- $pc->set_title(array('text'=>’My Simplest Graph'));
Add an animation
One thing pChart cannot do is animation. In phpChart, animations can be used simply by calling set_animate and passing the true value.
- $pc->set_animate(true);
That's it. At this time, your chart should already have titles and animations. The complete code is as follows:
- $pc = new C_PhpChartX(array(array(123, 34, 51, 22, 3)),'simplest_graph');
- $pc->set_animate(true);
- $pc->set_title(array('text'=>'My Simplest Graph'));
- $pc->draw();
Code essence
If you view the source in the browser, you will find that phpChart automatically contains many JavaScript and CSS files, including jquery. js, jquery-ui, and jqplot.js、jquery-ui.css. Although the chart is rendered in the browser using the client's JavaScript, all the code at the front end is PHP.
The reason for popularity is that JavaScript is no longer needed for me, a PHP developer, because phpChart will automatically process it for me. The following is all the JavaScript code generated when you view the source code-the result of the previous four lines of PHP code.