使用highcharts

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    
    <#assign ctx=request.contextPath/>
     <title>highcharts的使用</title>
    <script src="/static/jquery-3.2.1.js"></script>
    <script src="/static/highcharts.js"></script>
    
    <script>     $(document).ready(function () {
        $.ajax({
            url: "countAge",
            dataType: "json",
            method: "GET",
            success: function (data) {
                var userNames = [];
                var userAges = [];
                alert(data);
                $.each(data, function (index, item) {
                    userNames.push(item.name);
                    userAges.push(item.password);
                });
                showChart(userNames, userAges);
            }
        });
    });
    //显示图表
    function showChart(userNames, userAges) {
        var chart = {type: 'column'};
        var title = {text: '年龄最大的前三名用户'};
        var xAxis = {categories: ['用户'], crosshair: true};
        var yAxis = {min: 0, title: {text: '年龄 (岁)'}};
        var tooltip = {
            headerFormat: '<span style="font-size:10px">{point.key}</span><table>',
            pointFormat: '<tr><td style="color:{series.color};padding:0">{series.name}: </td>' + '<td style="padding:0"><b>{point.y} 岁</b></td></tr>',
            footerFormat: '</table>',
            shared: true,
            useHTML: true
        };
        var plotOptions = {column: {pointPadding: 0.2, borderWidth: 0}};
        var credits = {enabled: false};
        var series = [];
        for(var i=0;i<userNames.length;i++){
            series.push({name: userNames[i], data: [userAges[i]]});
        }
        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.credits = credits;
        $('#container').highcharts(json);
    }      </script>
    
</head>

<body> <h1>highcharts的使用</h1>
<div id="container" style="width: 550px; height: 400px; margin: 0 auto"></div>

</body>

</html>
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值