首页 > 代码库 > Highcharts之折线图
Highcharts之折线图
1 <!DOCTYPE html> 2 <html> 3 4 <head> 5 <meta charset="UTF-8"> 6 <title>Highcharts折线图举例</title> 7 <script src="http://www.mamicode.com/js/jquery-3.2.1.min.js"></script> 8 <script src="http://www.mamicode.com/js/highcharts.js"></script> 9 <script src="http://www.mamicode.com/js/highcharts.js"></script> 10 11 </head> 12 13 <body> 14 <div id="container" style="width: 1300px; height: 450px; margin: 0 auto"></div> 15 <div id="jsoner" style="width: 1300px; height: 450px; margin: 0 auto"></div> 16 <script language="JavaScript"> 17 $(document).ready(function() { 18 var chart = { 19 type: ‘line‘ 20 }; 21 var title = { 22 text: ‘<b>月平均气温统计表</b>‘ 23 }; 24 var subtitle = { 25 text: ‘来源:国家气象网‘ 26 }; 27 var xAxis = { 28 categories: [‘一月‘, ‘二月‘, ‘三月‘, ‘四月‘, ‘五月‘, ‘六月‘, ‘七月‘, ‘八月‘, ‘九月‘, ‘十月‘, ‘十一月‘, ‘十二月‘] 29 }; 30 var yAxis = { 31 title: { 32 text: ‘温度 (\xB0C)‘ 33 }, 34 plotLines: [{ 35 value: 0, 36 width: 1, 37 color: ‘#808080‘ 38 }] 39 }; 40 var plotOptions = { 41 line: { 42 dataLabels: { 43 enabled: true //图表中显示每个点的数值 44 }, 45 enableMouseTracking: true //鼠标悬停提示 46 } 47 }; 48 49 //提示后缀加单位 50 var tooltip = { 51 valueSuffix: ‘\xB0C‘ 52 }; 53 54 //设置图例的展示方式为右中对齐,非必须 55 var legend = { 56 layout: ‘vertical‘, 57 align: ‘right‘, 58 verticalAlign: ‘middle‘, 59 borderWidth: 0 60 }; 61 62 var series = [{ 63 name: ‘Tokyo‘, 64 data: [7.0, 6.9, 9.5, 14.5, 18.2, 21.5, 25.2, 65 26.5, 23.3, 18.3, 13.9, 9.6 66 ] 67 }, 68 { 69 name: ‘New York‘, 70 data: [-0.2, 0.8, 5.7, 11.3, 17.0, 22.0, 24.8, 71 24.1, 20.1, 14.1, 8.6, 2.5 72 ] 73 }, 74 { 75 name: ‘Berlin‘, 76 data: [-0.9, 0.6, 3.5, 8.4, 13.5, 17.0, 18.6, 77 17.9, 14.3, 9.0, 3.9, 1.0 78 ] 79 }, 80 { 81 name: ‘London‘, 82 data: [3.9, 4.2, 5.7, 8.5, 11.9, 15.2, 17.0, 83 16.6, 14.2, 10.3, 6.6, 4.8 84 ] 85 } 86 ]; 87 88 var json = {}; 89 json.chart = chart; 90 json.title = title; 91 json.subtitle = subtitle; 92 json.xAxis = xAxis; 93 json.yAxis = yAxis; 94 json.plotOptions = plotOptions; 95 json.tooltip = tooltip; 96 // json.legend = legend; //默认图例显示在图表下方就挺好,不需要调整故注释 97 json.series = series; 98 99 $(‘#container‘).highcharts(json); 100 // $(‘#jsoner‘).append("<p>"+JSON.stringify(json)+"</p>"); //检查JSON串 101 }); 102 103 </script> 104 105 </body> 106 107 </html>
运行结果:
Highcharts之折线图
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。