highcharts Example Tutorial Two: combine PHP with MySQL to generate pie chart, highcharts example Tutorial _php tutorial

Source: Internet
Author: User
Tags php and mysql

highcharts Example Tutorial Two: combine PHP with MySQL to generate pie chart, highcharts example tutorial


Last time we analyzed the use of highcharts combined with PHP and MySQL to generate a line chart example, we use the Technical CTO website search engine traffic as an example of using Highcharts to generate pie chart.
Pie charts are often used when we need to visually display the proportions of each part, such as the amount of traffic we need to count the major search engines.
First step: Create a Database save PV numbers for each search engine traffic
CREATE TABLE ' Pie ' (
' id ' int (ten) is not NULL auto_increment,
' title ' varchar (+) not NULL,
' PV ' int (ten) is not NULL,
PRIMARY KEY (' id ')
) Engine=myisam auto_increment=7 DEFAULT Charset=utf8;

The second step: write PHP code to get data, converted to Highcharts can render the data format, Highcharts can parse data in JSON format, such as: [' Baidu ', 120], [' Google ', 86];
Include_once (' connect.php ');
$res = mysql_query ("SELECT * from pie");
while ($row = Mysql_fetch_array ($res)) {
This means that the data is highlighted by default, and then we can not write
if ($row [' id ']==1) {
$arr 1[] = Array (
"Name" = $row [' title '],
"Y" = intval ($row [' PV ']),
"Sliced" = true,
"Selected" = True
);
}else{
$arr [] = Array (
$row [' title '],intval ($row [' PV '])
);
}
}
Merging arrays
$arrs = Array_merge ($arr 1, $arr);
$data = Json_encode ($arrs);
The need to pay special attention to the number of words must be added intval conversion, or highcharts will not recognize;




This article is from the technical cto:http://www.jscto.net, reproduced please indicate the source.


Using Highcharts with JS and MySQL to generate histogram problems

Tell you the train of thought, the rest of you have to find your own, up experience, rise posture Ah ~ ~ ~
After PHP reads the data, the organization data is in JSON format, called by the client, in the following format:
Category: ["School of Management", "....."]
Data: [[136,215], [147,196], ...
Client, first call the Highcharts.chart construction chart, set the basic type of the horizontal block stacked map
JS load data through AJAX, set the data to the category of the icon, series;
Chart.redraw can be.

You first look at the highcharts of all the sample, the more appropriate for you, directly after the copy, to find ways to modify the data.


Create a pie chart with highcharts How to add a click event to a pie chart, such as clicking a slice of a pie chart and jumping to a link

wrote a sample.
jsfiddle.net/uep3t/3/
Replace the alert inside the plotoption with a jump statement.

http://www.bkjia.com/PHPjc/861533.html www.bkjia.com true http://www.bkjia.com/PHPjc/861533.html techarticle Highcharts Example Tutorial two: combined with PHP and MySQL generated pie chart, highcharts instance tutorial back we analyzed the use of highcharts combined with PHP and MySQL generated line chart instances, this time we have a technology ...

  • Related Article

    Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.