Highcharts图表的setCategories
2013-12-09 10:58
253 查看
<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Highcharts Example</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 = [{name:"\u4e0a\u6d77","y":20},{"name":"\u5317\u4eac","y":10},{"name":"\u5929\u6d25","y":35}];
series.setData(data);
//类似这里,可以直接用set来添加,如同上面的setData都是加上set直接设置,很方便的改变x坐标的数据
chart.xAxis[0].setCategories(["2012-01-01","2012-03-03","2012-05-01","2012-08-01","2012-10-01","2012-11-11"]);
//chart.xAxis[1].setCategories(['Apples', 'Bananas', 'Oranges']);
//alert(chart.xAxis[0].categories.length);
alert(chart.xAxis[0].categories.length);
//chart.addSeries(series); //可以直接增加addSeries
}
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>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Highcharts Example</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 = [{name:"\u4e0a\u6d77","y":20},{"name":"\u5317\u4eac","y":10},{"name":"\u5929\u6d25","y":35}];
series.setData(data);
//类似这里,可以直接用set来添加,如同上面的setData都是加上set直接设置,很方便的改变x坐标的数据
chart.xAxis[0].setCategories(["2012-01-01","2012-03-03","2012-05-01","2012-08-01","2012-10-01","2012-11-11"]);
//chart.xAxis[1].setCategories(['Apples', 'Bananas', 'Oranges']);
//alert(chart.xAxis[0].categories.length);
alert(chart.xAxis[0].categories.length);
//chart.addSeries(series); //可以直接增加addSeries
}
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>
相关文章推荐
- Jquery图表控件Highcharts使用
- js中将字符串转换成json--(//highcharts图表里data数据源必须是数组形势的[{name="test1"},{name="test2"}])
- Highcharts JS——制作图表的纯js类库
- ASP.NET中动态获取数据使用Highcharts图表控件【Copy By Internet】
- Highcharts是一个制作图表的纯Javascript类库
- 使用JQuery结合HIghcharts实现从后台获取JSON实时刷新图表
- 图表highcharts联合jquery ajax 后端取数据前端图表渲染
- 关于highCharts加载出图表却不显示数据的问题
- Highcharts纯js图表库,以后可以跟客户说,你跟阿里云ECS用的图表库是同款
- 大数据时代的图表可视化利器——highcharts,D3和百度的echarts
- highcharts图表中级入门:图表手动放大缩小自动切换图表标题(title/subtitle)以及图例(legend)、credits字体示例呈现4 090. //图表放大
- [笔记]学习HighCharts的使用(不错的web图表插件)
- 利用Highcharts制作web图表学习(一)
- 网页图表Highcharts实践教程之外层图表区
- [highCharts入门]去除图表链接以及print download(导出,下载)
- Highcharts图表.net版开源,支持webform 和 mvc3,完全开源
- 图表控件Highcharts在AngularJS中的使用
- highcharts项目笔记-通过Ajax json数据绘制图表
- JS图表组件 highcharts 简单的介绍
- Highcharts纯Javascript图表使用讲解