highcharts柱状图demo

1.npm下载highcharts并引入项目(highcharts官网兼容 IE6+、完美支持移动端、图表类型丰富的 HTML5 交互图表 | Highcharts),或者直接在线引入都可以

2.新建.html文件,图表代码:

<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>第一个 Highcharts 图表</title>
</head>
<!-- 图表容器 DOM -->
<div id="container" style="width: 800px;height:500px;"></div>
<!-- 引入 highcharts.js -->
<script src="http://cdn.highcharts.com.cn/highcharts/highcharts.js"></script>
<script>
    // 图表配置
    var chart = Highcharts.chart('container', {
        chart: {
            type: 'bar'
        },
        title: {
            text: '各洲不同时间的人口条形图',
            style: {
                fontSize: '25px',
                color: 'red'
            }
        },
        subtitle: {
            text: '数据来源: Wikipedia.org',
            // align: 'right',
            style: {
                fontSize: '13px',
                // color: 'green'
            }
        },
        xAxis: {
            categories: ['非洲', '美洲', '亚洲', '欧洲', '大洋洲'],
            title: {
                text: '地区',
                style: {
                    fontSize: '15px',
                    color: 'red',
                },
            },
            labels: {
                rotation: -30  // 设置轴标签旋转角度
            },
            lineWidth: 1,
            lineColor: 'black',
        },
        yAxis: {
            min: 0,
            title: {
                text: '人口总量 (百万)',
                style: {
                    fontSize: '15px',
                    color: 'red',
                },
                // align: 'middle'
            },
            labels: {
                overflow: 'justify',
                rotation: 30, // 设置轴标签旋转角度
                style: {
                    fontSize: '10px',
                    color: 'skyblue',
                },
            },
            lineWidth: 1,
            lineColor: "green",
        },
        tooltip: {
            valueSuffix: ' 百万'
        },
        plotOptions: {
            bar: {
                dataLabels: {
                    style: {
                        fontSize: '10px',
                        color: 'red',
                    },
                    enabled: true,
                    allowOverlap: true // 允许数据标签重叠
                }
            }
        },
        legend: {
            layout: 'vertical',
            align: 'right',
            verticalAlign: 'top',
            verticalAlign:'middle',
            borderWidth: 1,
            shadow: true,
            itemStyle: {
                fontSize: '12px'
            }
        },
        series: [{
            name: '1800 年',
            data: [107, 31, 635, 203, 2],
        }, {
            name: '1900 年',
            data: [133, 156, 947, 408, 6],
            zones: [{
                color: 'gray'
            }]
        }, {
            name: '2008 年',
            data: [973, 914, 4054, 732, 34],
        }],
        credits: {

            enabled: false

        }
    });
</script>
</body>

</html>
<style scoped="sass">
    #container {
        margin: 0 auto;
    }
</style>

3.效果图:

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值