highcharts的学习和使用

本文提供了一系列Highcharts图表的实现案例,包括折线图、曲线图、面积图、堆叠面积图等多种类型,并展示了如何配置图表样式、交互效果及数据动态更新等功能。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>highcharts</title>
    <script src="http://apps.bdimg.com/libs/jquery/2.1.1/jquery.min.js"></script>
    <script src="https://img.hcharts.cn/highcharts/highcharts.js"></script>
</head>
<style>.p{width:50%;margin-left: -5px;overflow:hidden;display:inline-block;}</style>
<body>
<div class="p" id="main1"></div>
<script>
    Highcharts.chart("main1",{
        chart:{
            type:"line"
        },
        title:{
            text:"直线图"
        },
        xAxis:{
            categories:["Jan","Feb","Mar","Apr","May","Jun","Aug","Sep","Oct","Nov","Dev"]
        },
        series:[{
            data:[1,2,3,4,null,6,7,null,9],
            name:"Right"
        },{
            data:[5,5,7,8,null,13,7,null,12],
            step:"center",
            name:"Center"
        },{
            data:[8,9,10,11,null,12,13,null,15],
            step:"left",
            name:"Left"
        }],
    });
</script>
<div class="p" id="main2"></div>
<script>
    Highcharts.chart("main2",{
        chart:{
            type:"spline"
        },
        title:{
            text:"曲线图"
        },
        subtitle:{
            text:"2018"
        },
        xAxis:{
            categories:["Jan","Feb","Mar","Apr","May","Jun","Aug","Sep","Oct","Nov","Dev"]
        },
        series:[{
            type:"line",
            data:[1,5,2,4,null,6,8,5,9],
            name:"Right"
        },{
            data:[5,5,7,8,9,13,7,5,12],
            name:"Center"
        },{
            data:[8,9,10,11,null,12,13,null,15],
            name:"Left"
        }],
        plotOptions:{
            spline: {
                dataLabels: {
                    enabled: true
                },
                enableMouseTracking: false
            }
        }
    });
</script>
<div class="p">
<div id="main3" style="min-width:400px;height:400px"></div>
设置透明度:<span class="opacity">0.3</span>
<div class="range">
    <span class="min">0.1</span>
    <input type="range" min="0.1" max="1" step="0.1" value="0.3">
    <span class="max">1</span>
</div>
</div>
<script>
    $(function () {
        var chart = null;
        $('#main3').highcharts({
            chart: {
                type: 'area'
            },
            title: {
                text: '美苏核武器库存量'
            },
            subtitle: {
                text: '数据来源: <a href="https://thebulletin.metapress.com/content/c4120650912x74k7/fulltext.pdf">' +
                'thebulletin.metapress.com</a>'
            },
            xAxis: {
                allowDecimals: false,
                labels: {
                    formatter: function () {
                        return this.value; // clean, unformatted number for year
                    }
                }
            },
            yAxis: {
                title: {
                    text: '核武库国家'
                },
                labels: {
                    formatter: function () {
                        return this.value / 1000 + 'k';
                    }
                }
            },
            tooltip: {
                pointFormat: '{series.name} 制造 <b>{point.y:,.0f}</b>枚弹头'
            },
            plotOptions: {
                area: {
                    fillOpacity: 0.3, // 指定所有面积图的透明度
                    pointStart: 1940,
                    marker: {
                        enabled: false,
                        symbol: 'circle',
                        radius: 2,
                        states: {
                            hover: {
                                enabled: true
                            }
                        }
                    }
                }
            },
            series: [{
                name: '美国',
                data: [null, null, null, null, null, 6, 11, 32, 110, 235, 369, 640,
                    1005, 1436, 2063, 3057, 4618, 6444, 9822, 15468, 20434, 24126,
                    27387, 29459, 31056, 31982, 32040, 31233, 29224, 27342, 26662,
                    26956, 27912, 28999, 28965, 27826, 25579, 25722, 24826, 24605,
                    24304, 23464, 23708, 24099, 24357, 24237, 24401, 24344, 23586,
                    22380, 21004, 17287, 14747, 13076, 12555, 12144, 11009, 10950,
                    10871, 10824, 10577, 10527, 10475, 10421, 10358, 10295, 10104]
            }, {
                name: '苏联/俄罗斯',
                color: 'green',
                fillColor: {       // 设置渐变的填充颜色
                    linearGradient: {
                        x1: 0,
                        y1: 0,
                        x2: 0,
                        y2: 1
                    },
                    stops: [
                        [0, Highcharts.getOptions().colors[5]],
                        [1, Highcharts.Color(Highcharts.getOptions().colors[6]).setOpacity(0).get('rgba')]
                    ]
                },
                data: [null, null, null, null, null, null, null, null, null, null,
                    5, 25, 50, 120, 150, 200, 426, 660, 869, 1060, 1605, 2471, 3322,
                    4238, 5221, 6129, 7089, 8339, 9399, 10538, 11643, 13092, 14478,
                    15915, 17385, 19055, 21205, 23044, 25393, 27935, 30062, 32049,
                    33952, 35804, 37431, 39197, 45000, 43000, 41000, 39000, 37000,
                    35000, 33000, 31000, 29000, 27000, 25000, 24000, 23000, 22000,
                    21000, 20000, 19000, 18000, 18000, 17000, 16000]
            }]
        }, function(c) {
            chart = c;
        });
        // 动态更新透明度
        $('.range input').change(function(){
            var val = $(this).val();
            $('.opacity').html(val);
            chart.series[0].update({
                fillOpacity: val
            });
        });
    });
</script>
<div class="p" id="main4"></div>
<script>
    $("#main4").highcharts({
        chart: {
            type: 'area'
        },
        title: {
            text: '堆叠阶梯面积图'
        },
        plotOptions: {
            area: {
                stacking: 'normal',
                step: 'right'
            }
        },
        series: [{
            name: "示例数据1",
            data: [0, 1, 1, 1, 1, 2, 2, 2, 3, 3, 4, 2, 1, 1, 0, 0, 0, 0, 0]
        }, {
            name: "示例数据1",
            data: [0, 1, 1, 1, 1, 2, 2, 2, 3, 3, 4, 2, 1, 1, 0, 0, 0, 0, 0]
        }]
    });
</script>
<script src="http://cdn.hcharts.cn/highcharts/highcharts-more.js"></script>
<div class="p" id="main5"></div>
<script>
    $("#main5").highcharts({
        chart: {
            type: 'arearange'
        },
        title: {
            text: '面积范围图'
        },
        plotOptions: {
            arearange: {
            }
        },
        series: [{
            name: "示例数据1",
            data: [[1,1,3], [2,3,4], [3,3,5]]
        }]
    });
</script>
<div class="p" id="main6"></div>
<script>
    $("#main6").highcharts({
        chart: {
            type: 'areasplinerange'
        },
        title: {
            text: '曲线面积范围图'
        },
        plotOptions: {
            areasplinerange: {
            }
        },
        series: [{
            name: "示例数据1",
            data: [[1,1,3], [2,3,4], [3,3,5]]// x、y 的最低值、y 的最大值
        }]
    });
</script>
<div class="p" id="main7"></div>
<script>
    $(function () {
        var ranges = [
            [1246406400000, 14.3, 27.7],
            [1246492800000, 14.5, 27.8],
            [1246579200000, 15.5, 29.6],
            [1246665600000, 16.7, 30.7],
            [1246752000000, 16.5, 25.0],
            [1246838400000, 17.8, 25.7],
            [1246924800000, 13.5, 24.8],
            [1247011200000, 10.5, 21.4],
            [1247097600000, 9.2, 23.8],
            [1247184000000, 11.6, 21.8],
            [1247270400000, 10.7, 23.7],
            [1247356800000, 11.0, 23.3],
            [1247443200000, 11.6, 23.7],
            [1247529600000, 11.8, 20.7],
            [1247616000000, 12.6, 22.4],
            [1247702400000, 13.6, 19.6],
            [1247788800000, 11.4, 22.6],
            [1247875200000, 13.2, 25.0],
            [1247961600000, 14.2, 21.6],
            [1248048000000, 13.1, 17.1],
            [1248134400000, 12.2, 15.5],
            [1248220800000, 12.0, 20.8],
            [1248307200000, 12.0, 17.1],
            [1248393600000, 12.7, 18.3],
            [1248480000000, 12.4, 19.4],
            [1248566400000, 12.6, 19.9],
            [1248652800000, 11.9, 20.2],
            [1248739200000, 11.0, 19.3],
            [1248825600000, 10.8, 17.8],
            [1248912000000, 11.8, 18.5],
            [1248998400000, 10.8, 16.1]
        ];
        $('#main7').highcharts({
            title: {
                text: '某地7月份气温范围及平均值'
            },
            xAxis: {
                type: 'datetime',
                //tickInterval: 7 * 24 * 60 * 60 * 1000,
                dateTimeLabelFormats: {
                    week: '%Y-%m-%d'
                }
            },
            yAxis: {
                title: {
                    text: null
                }
            },
            tooltip: {
                crosshairs: true,
                shared: true,
                valueSuffix: '°C',
                pointFormatter: function () {
                    return this.series.name + ':<span style="color: red">' + this.low + '</span> ~ ' +
                        '<span style="color: green">' + this.high + '</span>';
                },
                dateTimeLabelFormats: {
                    day: '%Y-%m-%d'
                }
            },
            legend: {},
            series: [{
                name: '范围',
                data: ranges,
                type: 'arearange',
                linkedTo: ':previous',
                color: Highcharts.getOptions().colors[0],
                fillOpacity: 0.3,
                zIndex: 0,
                lineWidth: 1,
                dataLabels: {
                    enabled: true,
                    yLow: -20,  // x/y Low/High 分别控制低值数据标签的 x 或 y 偏移
                    xLow: 10,
                    yHigh: -10,
                    formatter: function () {
                        // this.point.below 表示当前的点是否是下方的点(即 low 点)
                        return '<span style="color:' +
                            (this.point.below ? 'red">' + this.point.low : 'green">' + this.point.high) +
                            '</span>';
                    }
                }
            }]
        });
    });
</script>
<div class="p" id="main8"></div>
<script>
    $('#main8').highcharts({
        chart: {
            type: 'column'
        },
        title: {
            text: '放置在柱子内部的数据标签'
        },
        xAxis: {
            categories: ['苹果', '橘子', '梨', '葡萄', '香蕉']
        },
        credits: {
            enabled: true
        },
        plotOptions: {
            column: {
                // 关于柱状图数据标签的详细配置参考:https://api.hcharts.cn/highcharts#plotOptions.column.dataLabels
                dataLabels: {
                    enabled: true,
                    // verticalAlign: 'top', // 竖直对齐方式,默认是 center
                    inside: true
                }
            }
        },
        series: [{
            name: '小张',
            data: [5, 3, 4, 7, 2]
        }, {
            name: '小彭',
            data: [2, -2, -3, 2, 1]
        }, {
            name: '小潘',
            data: [3, 4, 4, -2, 5]
        }]
    });
</script>
<div class="main9 p">
    <div id="main9" style="min-width:400px;height:400px"></div>
    <label>允许数据标签重叠 <input type="checkbox"></label>
    <p>
        (注:图中 非洲 1800 年、大洋洲 1900 年的数据标签因为没有足够空或会产生重叠的原因,所以在默认情况下不显示)
    </p>
</div>
<script>
    var chart9 = new Highcharts.Chart('main9', {
        chart: {
            type: 'bar'
        },
        title: {
            text: '各洲不同时间的人口条形图'
        },
        subtitle: {
            text: '数据来源: Wikipedia.org'
        },
        xAxis: {
            categories: ['非洲', '美洲', '亚洲', '欧洲', '大洋洲'],
            title: {
                text: null
            }
        },
        yAxis: {
            min: 0,
            title: {
                text: '人口总量 (百万)',
                align: 'high'
            },
            labels: {
                overflow: 'justify'
            }
        },
        tooltip: {
            valueSuffix: ' 百万'
        },
        plotOptions: {
            bar: {
                dataLabels: {
                    enabled: true
                    // ,allowOverlap 默认是 false,即不允许数据标签重叠
                }
            }
        },
        legend: {
            layout: 'vertical',
            align: 'right',
            verticalAlign: 'top',
            x: -40,
            y: 100,
            floating: true,
            borderWidth: 1,
            backgroundColor: ((Highcharts.theme && Highcharts.theme.legendBackgroundColor) || '#FFFFFF'),
            shadow: true
        },
        credits: {
            enabled: false
        },
        series: [{
            name: '1800 年',
            data: [107, 31, 635, 203, 2]
        }, {
            name: '1900 年',
            data: [133, 156, 947, 408, 6]
        }, {
            name: '2008 年',
            data: [973, 914, 4054, 732, 34]
        }]
    });
    $('.main9 input').click(function() {
        var val = $(this).prop('checked'),
            allowOverlap = val === 'on';
        console.log(val);
        chart9.update({
            plotOptions: {
                bar: {
                    dataLabels: {
                        allowOverlap: val
                    }
                }
            }
        });
    });
</script>
<style>#trellis td {
    width: 200px;
    height: 200px;
}
#trellis td.first {
    width: 300px;
}</style>
<table class="p" id="trellis">
    <tr>
        <td class="first"></td>
        <td></td>
        <td></td>
        <td></td>
    </tr>
</table>
<script>
    var charts = [],
    $containers = $('#trellis td'),
    datasets = [
        {
            name: '小明',
            data: [3, 6, 1, 2, 6]
        },
        {
            name: '小红',
            data: [5, 6, 4, 2, 1]
        },
        {
            name: '小张',
            data: [2, 6, 5, 2, 3]
        },
        {
            name: '小芳',
            data: [5, 2, 7, 4, 2]
        }];
    $.each(datasets, function(i, dataset) {
    charts.push(new Highcharts.Chart({
    chart: {
    renderTo: $containers[i],
    type: 'bar',
    marginLeft: i === 0 ? 100 : 10
    },
    title: {
    text: dataset.name,
    align: 'left',
    x: i === 0 ? 90 : 0
    },
    credits: {
    enabled: false
    },
    xAxis: {
    categories: ['苹果', '梨', '橙子', '香蕉', '胡萝卜'],
    labels: {
    enabled: i === 0
    }
    },
    yAxis: {
    allowDecimals: false,
    title: {
    text: null
    },
    min: 0,
    max: 10
    },
    legend: {
    enabled: false
    },
    series: [dataset]
    }));
    });
</script>
<div class="p" id="main10"></div>
<script>
    $('#main10').highcharts({
        chart: {
            plotBackgroundColor: null,
            plotBorderWidth: null,
            plotShadow: false
        },
        title: {
            text: '扇区突出演示'
        },
        tooltip: {
            headerFormat: '{series.name}<br>',
            pointFormat: '{point.name}: <b>{point.percentage:.1f}%</b>'
        },
        plotOptions: {
            pie: {
                allowPointSelect: true,
                cursor: 'pointer',
                dataLabels: {
                    enabled: true,
                    format: '<b>{point.name}</b>: {point.percentage:.1f} %',
                    style: {
                        color: (Highcharts.theme && Highcharts.theme.contrastTextColor) || 'black'
                    }
                },
                states: {
                    hover: {
                        enabled: false
                    }
                },
                slicedOffset: 20,         // 突出间距
                point: {                  // 每个扇区是数据点对象,所以事件应该写在 point 下面
                    events: {
                        // 鼠标滑过是,突出当前扇区
                        mouseOver: function() {
                            this.slice();
                        },
                        // 鼠标移出时,收回突出显示
                        mouseOut: function() {
                            this.slice();
                        },
                        // 默认是点击突出,这里屏蔽掉
                        click: function() {
                            return false;
                        }
                    }
                }
            }
        },
        series: [{
            type: 'pie',
            name: '浏览器访问量占比',
            data: [
                ['Firefox',   45.0],
                ['IE',       26.8],
                {
                    name: 'Chrome',
                    y: 12.8,
                    sliced: true, // 突出显示这个点(扇区),用于强调。
                },
                ['Safari',    8.5],
                ['Opera',     6.2],
                ['其他',   0.7]
            ]
        }]
    });
</script>
<div class="p" id="main11"></div>
<script>
main11f();
function main11f(){
    var colors = Highcharts.getOptions().colors,
        categories = ['IE', 'Firefox', 'Chrome', 'Safari', 'Opera'],
        data = [{
            y: 55.11,
            color: colors[0],
            drilldown: {
                name: 'IE 版本',
                categories: ['IE 6.0', 'IE 7.0', 'IE 8.0', 'IE 9.0'],
                data: [10.85, 7.35, 33.06, 2.81],
                color: colors[0]
            }
        }, {
            y: 21.63,
            color: colors[1],
            drilldown: {
                name: 'Firefox 版本',
                categories: ['Firefox 2.0', 'Firefox 3.0', 'Firefox 3.5', 'Firefox 3.6', 'Firefox 4.0'],
                data: [0.20, 0.83, 1.58, 13.12, 5.43],
                color: colors[1]
            }
        }, {
            y: 11.94,
            color: colors[2],
            drilldown: {
                name: 'Chrome 版本',
                categories: ['Chrome 5.0', 'Chrome 6.0', 'Chrome 7.0', 'Chrome 8.0', 'Chrome 9.0',
                    'Chrome 10.0', 'Chrome 11.0', 'Chrome 12.0'],
                data: [0.12, 0.19, 0.12, 0.36, 0.32, 9.91, 0.50, 0.22],
                color: colors[2]
            }
        }, {
            y: 7.15,
            color: colors[3],
            drilldown: {
                name: 'Safari 版本',
                categories: ['Safari 5.0', 'Safari 4.0', 'Safari Win 5.0', 'Safari 4.1', 'Safari/Maxthon',
                    'Safari 3.1', 'Safari 4.1'],
                data: [4.55, 1.42, 0.23, 0.21, 0.20, 0.19, 0.14],
                color: colors[3]
            }
        }, {
            y: 2.14,
            color: colors[4],
            drilldown: {
                name: 'Opera 版本',
                categories: ['Opera 9.x', 'Opera 10.x', 'Opera 11.x'],
                data: [ 0.12, 0.37, 1.65],
                color: colors[4]
            }
        }],
        browserData = [],
        versionsData = [],
        i,
        j,
        dataLen = data.length,
        drillDataLen,
        brightness;
    // 构建数据数组
    for (i = 0; i < dataLen; i += 1) {
        // 添加浏览器数据
        browserData.push({
            name: categories[i],
            y: data[i].y,
            color: data[i].color
        });
        // 添加版本数据
        drillDataLen = data[i].drilldown.data.length;
        for (j = 0; j < drillDataLen; j += 1) {
            brightness = 0.2 - (j / drillDataLen) / 5;
            versionsData.push({
                name: data[i].drilldown.categories[j],
                y: data[i].drilldown.data[j],
                color: Highcharts.Color(data[i].color).brighten(brightness).get()
            });
        }
    }
    // 创建图表
    $('#main11').highcharts({
        chart: {
            type: 'pie'
        },
        title: {
            text: '2011年4月浏览器市场份额'
        },
        subtitle: {
            text: '内环为浏览器品牌占比,外环为具体的版本'
        },
        yAxis: {
            title: {
                text: '总百分比市场份额'
            }
        },
        plotOptions: {
            pie: {
                shadow: false,
                center: ['50%', '50%']
            }
        },
        tooltip: {
            valueSuffix: '%'
        },
        series: [{
            name: '浏览器',
            data: browserData,
            size: '60%',
            dataLabels: {
                formatter: function () {
                    return this.y > 5 ? this.point.name : null;
                },
                color: 'white',
                distance: -30          // 距离值为负时显示在在扇区里面
            }
        }, {
            name: '版本',
            data: versionsData,
            size: '80%',
            innerSize: '60%',
            dataLabels: {
                softConnector: false,   // 是否使用曲线
                connectorColor: 'red', // 连接线颜色,默认是扇区颜色
                distance: 20, // 数据标签与扇区距离
                connectorPadding: 20,  // 数据标签与连接线的距离
                formatter: function () {
                    // 通过函数判断是否显示数据标签,为了防止数据标签过于密集
                    return this.y > 1 ? '<b>' + this.point.name + ':</b> ' + this.y + '%'  : null;
                }
            }
        }]
    });
}
</script>
<div class="p" id="main12"></div>
<script>
    main12f();
    function main12f(){
        var chart = null;
        $('#main12').highcharts({
            chart: {
                plotBackgroundColor: null,
                plotBorderWidth: null,
                plotShadow: false,
                spacing : [100, 0 , 40, 0]
            },
            title: {
                floating:true,
                text: '圆心显示的标题'
            },
            tooltip: {
                pointFormat: '{series.name}: <b>{point.percentage:.1f}%</b>'
            },
            plotOptions: {
                pie: {
                    showInLegend: true,
                    allowPointSelect: true,
                    cursor: 'pointer',
                    dataLabels: {
                        enabled: true,
                        format: '<b>{point.name}</b>: {point.percentage:.1f} %',
                        style: {
                            color: (Highcharts.theme && Highcharts.theme.contrastTextColor) || 'black'
                        }
                    },
                    point: {
                        events: {
                            mouseOver: function(e) {  // 鼠标滑过时动态更新标题
                                // 标题更新函数,API 地址:https://api.hcharts.cn/highcharts#Chart.setTitle
                                chart.setTitle({
                                    text: e.target.name+ '\t'+ e.target.y + ' %'
                                });
                            }
                            //,
                            // click: function(e) { // 同样的可以在点击事件里处理
                            //     chart.setTitle({
                            //         text: e.point.name+ '\t'+ e.point.y + ' %'
                            //     });
                            // }
                        }
                    },
                }
            },
            series: [{
                type: 'pie',
                innerSize: '80%',
                name: '市场份额',
                data: [
                    {name:'Firefox',   y: 45.0, url : 'http://bbs.hcharts.cn'},
                    ['IE',       26.8],
                    {
                        name: 'Chrome',
                        y: 12.8,
                        sliced: true,
                        selected: true,
                        url: 'http://www.hcharts.cn'
                    },
                    ['Safari',    8.5],
                    ['Opera',     6.2],
                    ['其他',   0.7]
                ]
            }]
        }, function(c) {
            // 环形图圆心
            var centerY = c.series[0].center[1],
                titleHeight = parseInt(c.title.styles.fontSize);
            c.setTitle({
                y:centerY + titleHeight/2
            });
            chart = c;
        });
    }
</script>
<div class="p" id="main13"></div>
<script>
    main13f();
    function main13f(){
        $('#main13').highcharts({
            chart: {
                plotBackgroundColor: null,
                plotBorderWidth: 0,
                plotShadow: false
            },
            title: {
                text: '浏览器<br>占比',
                align: 'center',
                verticalAlign: 'middle',
                y: 50
            },
            tooltip: {
                headerFormat: '{series.name}<br>',
                pointFormat: '{point.name}: <b>{point.percentage:.1f}%</b>'
            },
            plotOptions: {
                pie: {
                    dataLabels: {
                        enabled: true,
                        distance: -50,
                        style: {
                            fontWeight: 'bold',
                            color: 'white',
                            textShadow: '0px 1px 2px black'
                        }
                    },
                    startAngle: -90,
                    endAngle: 90,
                    center: ['50%', '75%']
                }
            },
            series: [{
                type: 'pie',
                name: '浏览器占比',
                innerSize: '50%',
                data: [
                    ['Firefox',   45.0],
                    ['IE',       26.8],
                    ['Chrome', 12.8],
                    ['Safari',    8.5],
                    ['Opera',     6.2],
                    {
                        name: '其他',
                        y: 0.7,
                        dataLabels: {
                            // 数据比较少,没有空间显示数据标签,所以将其关闭
                            enabled: false
                        }
                    }
                ]
            }]
        });
    }
</script>
<div id="main14" class="p"></div>
<script>
    main14f();
    function main14f(){
        (function (H) {
            function symbolWrap(proceed, symbol, x, y, w, h, options) {
                if (symbol.indexOf('text:') === 0) {
                    var text = symbol.split(':')[1],
                        svgElem = this.text(text, x, y)
                            .attr({
                                translateY: h,
                                translateX: -1
                            })
                            .css({
                                fontFamily: 'FontAwesome',
                                fontSize: h * 2
                            });
                    if (svgElem.renderer.isVML) {
                        svgElem.fillSetter = function (value, key, element) {
                            element.style.color = H.Color(value).get('rgb');
                        };
                    }
                    return svgElem;
                }
                return proceed.apply(this, [].slice.call(arguments, 1));
            }
            H.wrap(H.SVGRenderer.prototype, 'symbol', symbolWrap);
            if (H.VMLRenderer) {
                H.wrap(H.VMLRenderer.prototype, 'symbol', symbolWrap);
            }
            // Load the font for SVG files also
            H.wrap(H.Chart.prototype, 'getSVG', function (proceed) {
                var svg = proceed.call(this);
                svg = '<?xml-stylesheet type="text/css" ' +
                    'href="http://netdna.bootstrapcdn.com/font-awesome/4.1.0/css/font-awesome.min.css" ?>' +
                    svg;
                return svg;
            });
        }(Highcharts));
        $('#main14').highcharts({
            chart: {
                type: 'scatter'
            },
            title: {
                text: '自定义数据点图标'
            },
            subtitle: {
                text: '使用 Font Awesome 图标的散点图'
            },
            yAxis: {
                title: {
                    text: '体重(kg)'
                }
            },
            xAxis: {
                title: {
                    text: '身高(cm)',
                    y: 20,
                    x: -30,
                    offset: 0,
                    align: 'low'
                }
            },
            tooltip: {
                shared: true,
                pointFormat: '<span style="color:{series.color}; font-family: FontAwesome">{series.options.icon}</span> {series.name}: <b>[{point.x}, {point.y}]</b><br/>'
            },
            plotOptions: {
                scatter: {
                    marker: {
                        states: {
                            hover: {
                                enabled: false,
                                lineWidth: 0
                            }
                        }
                    }
                },
                series: {
                    cursor: 'default'
                }
            },
            series: [{
                data: [[174.0, 65.6], [175.3, 71.8], [193.5, 80.7], [186.5, 72.6], [187.2, 78.8],
                    [181.5, 74.8], [184.0, 86.4], [184.5, 78.4], [175.0, 62.0], [184.0, 81.6],
                    [180.0, 76.6], [177.8, 83.6], [192.0, 90.0], [176.0, 74.6], [174.0, 71.0],
                    [184.0, 79.6], [192.7, 93.8], [171.5, 70.0], [173.0, 72.4], [176.0, 85.9],
                    [176.0, 78.8], [180.5, 77.8], [172.7, 66.2], [176.0, 86.4], [173.5, 81.8],
                    [178.0, 89.6], [180.3, 82.8], [180.3, 76.4], [164.5, 63.2], [173.0, 60.9]] ,
                marker: {
                    symbol: 'text:\uf183' // fa-male
                },
                icon: '\uf183',
                name: '男性',
                color: 'rgba(119, 152, 191, 0.6)'
            }, {
                data: [[161.2, 51.6], [167.5, 59.0], [159.5, 49.2], [157.0, 63.0], [155.8, 53.6],
                    [170.0, 59.0], [159.1, 47.6], [166.0, 69.8], [176.2, 66.8], [160.2, 75.2],
                    [172.5, 55.2], [170.9, 54.2], [172.9, 62.5], [153.4, 42.0], [160.0, 50.0],
                    [147.2, 49.8], [168.2, 49.2], [175.0, 73.2], [157.0, 47.8], [167.6, 68.8],
                    [159.5, 50.6], [175.0, 82.5], [166.8, 57.2], [176.5, 87.8], [170.2, 72.8],
                    [174.0, 54.5], [173.0, 59.8], [179.9, 67.3], [170.5, 67.8], [160.0, 47.0],
                    [154.4, 46.2], [162.0, 55.0], [176.5, 83.0], [160.0, 54.4], [152.0, 45.8]],
                marker: {
                    symbol: 'text:\uf182' // fa-female
                },
                icon: '\uf182',
                name: '女性',
                color: 'rgba(223, 83, 83, 0.6)'
            }]
        });
    }
</script>
<div id="main15" class="p"></div>
<script>
    main15f();
    function main15f(){
        $('#main15').highcharts({
            chart: {
                zoomType: 'xy'
            },
            title: {
                text: '误差图'
            },
            xAxis: [{
                categories: ['一月', '二月', '三月', '四月', '五月', '六月', '七月', '八月', '九月', '十月', '十一月', '十二月']
            }],
            yAxis: [{ // Secondary yAxis
                title: {
                    text: '降水',
                    style: {
                        color: Highcharts.getOptions().colors[0]
                    }
                },
                labels: {
                    format: '{value} mm',
                    style: {
                        color: Highcharts.getOptions().colors[0]
                    }
                },
                opposite: true
            }],
            tooltip: {
                shared: true
            },
            plotOptions: {
                errorbar: {
                    lineWidth: 2,
                    whiskerWidth: 1,
                    stemColor: 'red',
                    // stemDashStyle: 'Dash',
                    whiskerLength: '40%'
                }
            },
            series: [{
                name: '降水',
                type: 'column',
                data: [49.9, 71.5, 106.4, 129.2, 144.0, 176.0, 135.6, 148.5, 216.4, 194.1, 95.6, 54.4],
                tooltip: {
                    pointFormat: '<span style="font-weight: bold; color: {series.color}">{series.name}</span>: <b>{point.y:.1f} mm</b> '
                }
            }, {
                name: '降雨误差',
                type: 'errorbar',
                data: [[48, 51], [68, 73], [92, 110], [128, 136], [140, 150], [171, 179], [135, 143], [142, 149], [204, 220], [189, 199], [95, 110], [52, 56]],
                tooltip: {
                    pointFormat: '(误差范围: {point.low}-{point.high} mm)<br/>'
                }
            }]
        });
    }
</script>
<div class="p">
<div id="main16"></div>
<div class="main16">
<div class="range">
    <p>宽度 <span class="val">40%</span></p>
    0% <input type="range" value="40" min="0" max="100" step="10" data-type="height"> 100%
</div>
<div class="range">
    <p>高度 <span class="val">30%</span></p>
    0% <input type="range" value="30" min="0" max="100" step="10" data-type="width"> 100%
</div>
</div>
</div>
<script src="https://img.hcharts.cn/highcharts/modules/funnel.js"></script>
<script>
    main16f();
    function main16f(){
        var chart = new Highcharts.Chart('main16', {
            chart: {
                type: 'funnel',
                marginRight: 100
            },
            title: {
                text: '销售漏斗',
                x: -50
            },
            plotOptions: {
                series: {
                    minPointLength: 200,
                    dataLabels: {
                        enabled: true,
                        format: '<b>{point.name}</b> ({point.y:,.0f})',
                        color: (Highcharts.theme && Highcharts.theme.contrastTextColor) || 'black',
                        softConnector: true
                    },
                    neckWidth: '40%',
                    neckHeight: '35%',
                    //-- Other available options
                    // height: pixels or percent
                    // width: pixels or percent
                }
            },
            legend: {
                enabled: false
            },
            series: [{
                name: '用户',
                data: [
                    ['访问网站',   15654],
                    ['下载产品',       4064],
                    ['询价', 1987],
                    ['发送合同',    976],
                    ['成交',    846]
                ]
            }]
        });
        var range = {
            neckWidth: 40,
            neckHeight: 30
        };
        $('.main16 input[type="range"]').change(function() {
            var _this = $(this),
                type = _this.data('type'),
                val = _this.val();
            _this.parent().find('.val').html(val + '%');
            if(type === 'width') {
                range.neckWidth = val + '%';
            } else {
                range.neckHeight = val + '%';
            }
            chart.series[0].update(range);
        });
    }
</script>
<div id="main17" class="p"></div>
<script>
    main17f();
    function main17f(){
        $('#main17').highcharts({
            chart: {
                type: 'funnel',
                marginRight: 100,
                events: {
                    load: function() {
                        var chart = this;
                        Highcharts.each(chart.series[0].data, function(p, i) {
                            p.dataLabel.attr({
                                x: (chart.plotWidth - chart.plotLeft) / 2,
                                'text-anchor': 'middle'
                            });
                        });
                    },
                    redraw: function() {
                        var chart = this;
                        Highcharts.each(chart.series[0].data, function(p, i) {
                            p.dataLabel.attr({
                                x: (chart.plotWidth - chart.plotLeft) / 2,
                                'text-anchor': 'middle'
                            });
                        });
                    }
                }
            },
            title: {
                text: 'Sales funnel',
                x: -50
            },
            plotOptions: {
                series: {
                    dataLabels: {
                        connectorWidth: 0,
                        distance: 0,
                        enabled: true,
                        format: '<b>{point.name}</b> ({point.y:,.0f})',
                        color: (Highcharts.theme && Highcharts.theme.contrastTextColor) || 'black',
                        softConnector: true,
                        crop: false
                    },
                    neckWidth: '30%',
                    neckHeight: '25%'
                    //-- Other available options
                    // height: pixels or percent
                    // width: pixels or percent
                }
            },
            legend: {
                enabled: false
            },
            series: [{
                name: 'Unique users',
                data: [
                    ['访问网站',   15654],
                    ['下载软件',       4064],
                    ['询问价格', 1987],
                    ['发送报价',    976],
                    ['成功',    846]
                ]
            }]
        });
    }
</script>
<div id="main18" class="p"></div>
<script>
    main18f();
    function main18f(){
        $('#main18').highcharts({
            chart: {
                type: 'pyramid',
                marginRight: 100
            },
            title: {
                text: 'Sales pyramid',
                x: -50
            },
            plotOptions: {
                series: {
                    //reversed: false,配置 reversed 可以让金字塔倒立,其效果和将 neckWidth 和 neckHeight 设置为 0 的漏斗图一样。
                    dataLabels: {
                        enabled: true,
                        format: '<b>{point.name}</b> ({point.y:,.0f})',
                        color: (Highcharts.theme && Highcharts.theme.contrastTextColor) || 'black',
                        softConnector: true
                    }
                }
            },
            legend: {
                enabled: false
            },
            series: [{
                name: 'Unique users',
                data: [
                    ['Website visits',   15654],
                    ['Downloads',       4064],
                    ['Requested price list', 1987],
                    ['Invoice sent',    976],
                    ['Finalized',    846]
                ]
            }]
        });
    }
</script>
<div id="main19" class="p"></div>
<script>
    main19f();
    function main19f(){
        $('#main19').highcharts({
            chart: {
                type: 'waterfall'
            },
            title: {
                text: '2016 年某公司人员变动情况'
            },
            xAxis: {
                type: 'category'
            },
            yAxis: {
                title: {
                    text: 'USD'
                }
            },
            legend: {
                enabled: false
            },
            tooltip: {
                pointFormat: '<b>{point.y}</b>人 {point.label}'
            },
            series: [{
                upColor: 'green',//上升的柱子颜色(即正值的颜色)
                borderWidth: 0,
                minPointLength: 5,
                color: 'red',
                data: [{
                    name: 'Q1.2015',
                    color: '#66B3FF',
                    label: '初创团队',
                    y: 5
                }, {
                    name: 'Q2.2015',
                    y: 2
                }, {
                    name: 'Q3.2015',
                    y: -1
                }, {
                    name: '15年总数',
                    isIntermediateSum: true,
                    color: '#006CEE'
                }, {
                    name: 'Q1.2016',
                    y: 5,
                    label: '团队扩招',
                    color: 'yellow'
                }, {
                    name: 'Q2.2016',
                    y: 1
                },{
                    name: 'Q3 & Q4',
                    y: 0,
                    color: '#000'
                }, {
                    name: '16年总数',
                    color: '#006CEE',
                    isSum: true
                },{
                    name: 'Q1.2017',
                    y:2
                },{
                    name: '总数',
                    isSum: true,
                    color: Highcharts.getOptions().colors[1]
                }],
                dataLabels: {
                    enabled: true,
                    style: {
                        color: '#FFFFFF',
                        fontWeight: 'bold',
                        textShadow: '0px 0px 3px black'
                    }
                },
                pointPadding: 0
            }]
        });
    }
</script>
<div id="main20" class="p"></div>
<script>
    main20f();
    function main20f(){
        $('#main20').highcharts({
            chart: {
                polar: true
            },
            title: {
                text: '极地图'
            },
            pane: {
                startAngle: 0,
                endAngle: 360
            },
            xAxis: {
                tickInterval: 45,
                min: 0,
                max: 360,
                labels: {
                    formatter: function () {
                        return this.value + '°';
                    }
                }
            },
            yAxis: {
                min: 0
            },
            plotOptions: {
                series: {
                    pointStart: 0,
                    pointInterval: 45
                },
                column: {
                    pointPadding: 0,
                    groupPadding: 0
                }
            },
            series: [{
                type: 'column',
                name: '柱形',
                data: [8, 7, 6, 5, 4, 3, 2, 1],
                pointPlacement: 'between'
            }, {
                type: 'line',
                name: '线',
                data: [1, 2, 3, 4, 5, 6, 7, 8]
            }, {
                type: 'area',
                name: '面积',
                data: [1, 8, 2, 7, 3, 6, 4, 5]
            }]
        });
    }
</script>
<div id="main21" class="p"></div>
<script>
    main21f();
    function main21f(){
        var charts = new Highcharts.Chart({
            chart: {
                renderTo:"main21",
                polar: true,
                type: 'line'
            },
            credits:{
                enabled:false//去除右下角网址
            },
            title: {
                text: '预算与支出',
                x: -80
            },
            pane: {
                size: '80%'
            },
            xAxis: {
                categories: ['销售', '市场营销', '发展', '客户支持',
                    '信息技术', '行政管理'],
                tickmarkPlacement: 'on',
                lineWidth: 0
            },
            yAxis: {
                gridLineInterpolation: 'polygon',
                lineWidth: 0,
                min: 0
            },
            tooltip: {
                shared: true,
                pointFormat: '<span style="color:{series.color}">{series.name}: <b>${point.y:,.0f}</b><br/>'
            },
            legend: {
                align: 'right',
                verticalAlign: 'top',
                y: 70,
                layout: 'vertical'
            },
            series: [{
                name: '预算拨款',
                data: [43000, 19000, 60000, 35000, 17000, 10000],
                pointPlacement: 'on'
            }, {
                name: '实际支出',
                data: [50000, 39000, 42000, 31000, 26000, 14000],
                pointPlacement: 'on'
            }]
        });
    }
</script>
<div id="main22" class="p"></div>
<script>
    main22f();
    function main22f(){
        var charts = new Highcharts.Chart({
            chart: {
                renderTo:"main22",
                polar: true,
                type: 'line'
            },
            credits:{
                enabled:false//去除右下角网址
            },
            title: {
                text: '预算与支出',
                x: -80
            },
            pane: {
                size: '80%'
            },
            xAxis: {
                categories: ['销售', '市场营销', '发展', '客户支持',
                    '信息技术', '行政管理'],
                tickmarkPlacement: 'on',
                lineWidth: 0
            },
            yAxis: {
                gridLineInterpolation: 'polygon',
                lineWidth: 0,
                min: 0
            },
            tooltip: {
                shared: true,
                useHTML:true,
                headerFormat:'<div><p style="text-align:center;">{point.key}</p>',
                pointFormat: '<span style="color:{series.color}">{series.name}: <b>${point.y}</b><br/>',
                footerFormat:'</div>',
            },
            legend: {
                align: 'right',
                verticalAlign: 'top',
                y: 70,
                layout: 'vertical'
            },
            series: [{
                name: '预算拨款',
                data: [43000, 19000, 60000, 35000, 17000, 10000],
                pointPlacement: 'on'
            }, {
                name: '实际支出',
                data: [50000, 39000, 42000, 31000, 26000, 14000],
                pointPlacement: 'on'
            }]
        });
    }
</script>
</body>
</html>

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值