版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/chengqiuming/article/details/85008415
一 代码
<html>
<head>
<meta charset="UTF-8" />
<title>Highcharts 堆叠条形图</title>
<script src="http://apps.bdimg.com/libs/jquery/2.1.4/jquery.min.js"></script>
<script src="http://code.highcharts.com/highcharts.js"></script>
</head>
<body>
<div id="container" style="width: 550px; height: 400px; margin: 0 auto"></div>
<script language="JavaScript">
$(document).ready(function() {
// 条形图
var chart = {
type: 'bar'
};
// 主标题
var title = {
text: '世界范围历史人口分列'
};
// 子标题
var subtitle = {
text: '世界范围'
};
// X 轴
var xAxis = {
categories: ['非洲', '美洲', '亚洲', '欧洲', '大洋洲'],
title: {
text: null
}
};
// Y 轴
var yAxis = {
min: 0,
title: {
text: '人口 (百万)',
align: 'high'
},
labels: {
overflow: 'justify'
}
};
var tooltip = {
valueSuffix: ' 百万'
};
var plotOptions = {
bar: {
dataLabels: {
enabled: true
}
},
//配置图表堆叠使用 plotOptions.series.stacking,并设置为 "normal"。
//如果禁用堆叠可设置为 null , "normal" 通过值设置堆叠, "percent" 堆叠则按百分比。
series: {
stacking: 'normal'
}
};
var legend = {
layout: 'vertical',
align: 'right',
verticalAlign: 'top',
x: -40,
y: 100,
floating: true,
borderWidth: 1,
backgroundColor: ((Highcharts.theme && Highcharts.theme.legendBackgroundColor) || '#FFFFFF'),
shadow: true
};
var credits = {
enabled: false
};
// 数据
var series= [{
name: 'Year 1800',
data: [107, 31, 635, 203, 2]
}, {
name: 'Year 1900',
data: [133, 156, 947, 408, 6]
}, {
name: 'Year 2008',
data: [973, 914, 4054, 732, 34]
}
];
var json = {};
json.chart = chart;
json.title = title;
json.subtitle = subtitle;
json.tooltip = tooltip;
json.xAxis = xAxis;
json.yAxis = yAxis;
json.series = series;
json.plotOptions = plotOptions;
json.legend = legend;
json.credits = credits;
$('#container').highcharts(json);
});
</script>
</body>
</html>
二 运行结果