Highcharts柱状图数据展示代码
2013-12-09 10:58
218 查看
前端<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>z</title>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.2/jquery.min.js"></script>
<script type="text/javascript">
$(function () {
function requestData() {
//setTimeout(requestData, 3000);
$.getJSON('etc.php',displayData);
}
function displayData(dataJSON)
{
var series = chart.series[0];
var data = dataJSON;
series.setData(data);
categories = setCate(data);
chart.xAxis[0].setCategories(categories);
}
function setCate(data)
{
var arr = [];
for(var i in data)
{
arr.push(data[i]['name']);
}
return arr;
}
chart = new Highcharts.Chart({
chart: {
renderTo: 'container',
type: 'column',
margin: [ 50, 50, 100, 80],
events: {
load: requestData
}
},
title: {
text: 'World\'s largest cities per 2008'
},
plotOptions: {
pie: {
allowPointSelect: true,
cursor: 'pointer',
dataLabels: {
enabled: false
},
showInLegend: true
}
},
/*
xAxis: {
categories: [
'Tokyo',
'Jakarta',
'New York',
'Seoul',
'Manila',
'Mumbai',
'Sao Paulo',
'Mexico City',
'Dehli',
'Osaka',
'Cairo',
'Kolkata',
'Los Angeles',
'Shanghai',
'Moscow',
'Beijing',
'Buenos Aires',
'Guangzhou',
'Shenzhen',
'Istanbul',
''
],
labels: {
rotation: -45,
align: 'right',
style: {
fontSize: '13px',
fontFamily: 'Verdana, sans-serif'
}
}
},
*/
yAxis: {
min: 0,
title: {
text: 'Population (millions)'
}
},
legend: {
enabled: false
},
tooltip: {
pointFormat: 'Population in 2008: <b>{point.y:.1f} millions</b>',
},
series: [{
name: 'Population',
data: [
{name:'aa', y:35},
34.4, 21.8, 20.1, 20, 19.6, 19.5, 19.1, 18.4, 18,
17.3, 16.8, 15, 14.7, 14.5, 13.3, 12.8, 12.4, 11.8,
11.7, 11.2],
dataLabels: {
enabled: true,
rotation: -90,
color: '#FFFFFF',
align: 'right',
x: 4,
y: 10,
style: {
fontSize: '13px',
fontFamily: 'Verdana, sans-serif',
textShadow: '0 0 3px black'
}
}
}]
});
});
</script>
</head>
<body>
<script src="js/hc.js"></script>
<script src="js/modules/exporting.js"></script>
<div id="container" style="min-width: 500px; height: 400px; margin: 0 auto"></div>
</body>
</html>
后端php
<?php
// Set the JSON header
header("Content-type: text/json");
area();
/**
* 地区接口
* name名称
* y数据值
*
*/
function area()
{
$b = array(
array('name'=>'上海', 'y'=>28.2),
array('name'=>'北京', 'y'=>48.2),
array('name'=>'广东', 'y'=>18.2),
);
$data = json_encode($b);
echo($data);
}
?>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>z</title>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.2/jquery.min.js"></script>
<script type="text/javascript">
$(function () {
function requestData() {
//setTimeout(requestData, 3000);
$.getJSON('etc.php',displayData);
}
function displayData(dataJSON)
{
var series = chart.series[0];
var data = dataJSON;
series.setData(data);
categories = setCate(data);
chart.xAxis[0].setCategories(categories);
}
function setCate(data)
{
var arr = [];
for(var i in data)
{
arr.push(data[i]['name']);
}
return arr;
}
chart = new Highcharts.Chart({
chart: {
renderTo: 'container',
type: 'column',
margin: [ 50, 50, 100, 80],
events: {
load: requestData
}
},
title: {
text: 'World\'s largest cities per 2008'
},
plotOptions: {
pie: {
allowPointSelect: true,
cursor: 'pointer',
dataLabels: {
enabled: false
},
showInLegend: true
}
},
/*
xAxis: {
categories: [
'Tokyo',
'Jakarta',
'New York',
'Seoul',
'Manila',
'Mumbai',
'Sao Paulo',
'Mexico City',
'Dehli',
'Osaka',
'Cairo',
'Kolkata',
'Los Angeles',
'Shanghai',
'Moscow',
'Beijing',
'Buenos Aires',
'Guangzhou',
'Shenzhen',
'Istanbul',
''
],
labels: {
rotation: -45,
align: 'right',
style: {
fontSize: '13px',
fontFamily: 'Verdana, sans-serif'
}
}
},
*/
yAxis: {
min: 0,
title: {
text: 'Population (millions)'
}
},
legend: {
enabled: false
},
tooltip: {
pointFormat: 'Population in 2008: <b>{point.y:.1f} millions</b>',
},
series: [{
name: 'Population',
data: [
{name:'aa', y:35},
34.4, 21.8, 20.1, 20, 19.6, 19.5, 19.1, 18.4, 18,
17.3, 16.8, 15, 14.7, 14.5, 13.3, 12.8, 12.4, 11.8,
11.7, 11.2],
dataLabels: {
enabled: true,
rotation: -90,
color: '#FFFFFF',
align: 'right',
x: 4,
y: 10,
style: {
fontSize: '13px',
fontFamily: 'Verdana, sans-serif',
textShadow: '0 0 3px black'
}
}
}]
});
});
</script>
</head>
<body>
<script src="js/hc.js"></script>
<script src="js/modules/exporting.js"></script>
<div id="container" style="min-width: 500px; height: 400px; margin: 0 auto"></div>
</body>
</html>
后端php
<?php
// Set the JSON header
header("Content-type: text/json");
area();
/**
* 地区接口
* name名称
* y数据值
*
*/
function area()
{
$b = array(
array('name'=>'上海', 'y'=>28.2),
array('name'=>'北京', 'y'=>48.2),
array('name'=>'广东', 'y'=>18.2),
);
$data = json_encode($b);
echo($data);
}
?>
相关文章推荐
- 一套非常标准的数据请求和数据展示代码的模板
- EasyUI——实现展示后台数据代码
- .net之工作流工程展示及代码分享(三)数据存储引擎
- iOS 0行代码实现 TableView 无数据时展示占位视图
- Highcharts 多个Y轴动态刷新数据的实现代码
- Vue 中使用vue2-highcharts实现曲线数据展示示例
- d3实现横向柱状图数据展示(V4)
- highcharts柱状图和饼图的数据填充
- 【iOS代码】Json数据展示为联系人效果的TableView
- highcharts动态获取数据生成柱状图
- highCharts怎样实现json数组数据的图形展示
- highcharts绘制折线数据图代码实例
- 用Dreamweaver将数据库中的数据以柱状图的形式动态展示于网页中
- HighCharts 随机数动态曲线展示(动态数据实时展示)
- JavaScript根据数据生成百分比图和柱状图的实例代码
- 数据从数据库到java代码再到前台页面展示流程
- iOS 0行代码实现 TableView 无数据时展示占位视图
- Vue 中使用vue2-highcharts实现曲线数据展示的方法
- Vue 中使用vue2-highcharts实现实时曲线数据展示示例
- EasyUI——实现展示后台数据代码