Highcharts常用几种图表
基于Highcharts版本: 4.2.3几种常见的图表,更多用法可以参考官方文档
柱状图
<!DOCTYPE html> <html> <head lang="en"> <meta charset="UTF-8"> <title>HignChartsDemo</title> <script src="js/jquery-1.8.0.min.js"></script> <script src="js/highcharts.js"></script> </head> <script type="text/javascript"> $(function () { $('#container').highcharts({ //图表展示容器,与div的id保持一致 chart: { type: 'column' //指定图表的类型,默认是折线图(line) }, title: { //text: '我的第一个图表' //指定图表标题 //text:null, //不显示标题 useHTML: true, text: "Highcharts中文网 | <a href='http://www.hcharts.cn' target='_blank'>中文教程</a>" }, margin: {}, subtitle: { //非必须 text: '我是副标题', style: { color: '#f00', fontSize: '12px' } }, xAxis: { title: {text: 'x title'}, categories: ['my', 'first', 'chart'] //指定x轴分组 }, yAxis: { title: { text: 'something' //指定y轴的标题 } }, series: [{ //指定数据列 name: 'Jane', //数据列名 data: [1, 3, 4] //数据 }, { name: 'John', data: [5, 7, 3] }], credits: { enabled: false //去掉Highcharts.com } }); }); </script> <body> <div id="container" style="width:500px;height:400px"></div> </body> </html>
折线图
<!DOCTYPE html> <html> <head lang="en"> <meta charset="UTF-8"> <title>Demo</title> <script src="js/jquery-1.8.0.min.js"></script> <script src="js/highcharts.js"></script> </head> <script type="text/javascript"> $(function () { $('#container').highcharts({ //图表展示容器,与div的id保持一致 chart: { type: 'line' //指定图表的类型,默认是折线图(line) }, title: { //text: '我的第一个图表' //指定图表标题 //text:null, //不显示标题 useHTML: true, text: "Highcharts中文网 | <a href='http://www.hcharts.cn' target='_blank'>中文教程</a>", margin: 15 }, subtitle: { //非必须 text: '我是副标题', style: { color: '#f00', fontSize: '10px', fontWeight: "blod", fontFamily: "Courier new", }, }, xAxis: { title: {text: 'x title'}, categories: ['一月', '二月', '三月', '四月', '五月', '六月', '七月', '八月', '九月'] //指定x轴分组 }, yAxis: { title: { text: 'something' //指定y轴的标题 }, labels: { formatter: function () { if (this.value <= 100) { return "第一等级(" + this.value + ")"; } else if (this.value > 100 && this.value <= 200) { return "第二等级(" + this.value + ")"; } else { return "第三等级(" + this.value + ")"; } } } }, series: [{ //指定数据列 name: 'Jane', //数据列名 data: [100, 300, 130, 250, 128, 370, 234, 423, 232], //数据 lineWidth: 2, //线条宽度 dashStyle: 'dash', //线条的样式 color:"#ff0000" //线条颜色 }, { name: 'John', data: [432, 245, 230, 400, 600, 400, 20, 360, 200], //多个数据列单独指定前后缀 tooltip: { valueSuffix: '°C' } } ], plotOptions: { //使数据点可选择 series: { allowPointSelect: true }, line: { //显示数据标签 dataLabels: { enabled: true } } }, //提示框值的前缀、后缀 tooltip: { //enabled : false, //禁用提示框 valuePrefix: '¥', valueSuffix: '元', //提示框外观 backgroundColor: '#FCFFC5', // 背景颜色 borderColor: 'black', // 边框颜色 borderRadius: 10, // 边框圆角 borderWidth: 3, // 边框宽度 shadow: true, // 是否显示阴影 animation: true, // 是否启用动画效果 style: { // 文字内容相关样式 color: "#ff0000", fontSize: "12px", fontWeight: "blod", fontFamily: "Courir new" } }, credits: { enabled: false //去掉Highcharts.com } }); }); </script> <body> <div id="container" style="width:500px;height:400px"></div> </body> </html>
饼状图
<!DOCTYPE HTML> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> <title>Highcharts Example</title> <script type="text/javascript" src="http://cdn.hcharts.cn/jquery/jquery-1.8.3.min.js"></script> <script type="text/javascript"> $(function () { $('#container').highcharts({ chart: { plotBackgroundColor: null, plotBorderWidth: null, plotShadow: false, type: 'pie' }, title: { text: 'Browser market shares January, 2015 to May, 2015' }, tooltip: { pointFormat: '{series.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' } }, showInLegend: true } }, series: [{ name: 'Brands', colorByPoint: true, data: [{ name: 'Microsoft Internet Explorer', y: 56.33 }, { name: 'Chrome', y: 24.03, sliced: true, selected: true }, { name: 'Firefox', y: 10.38 }, { name: 'Safari', y: 4.77 }, { name: 'Opera', y: 0.91 }, { name: 'Proprietary or Undetectable', y: 0.2 }], }] }); }); </script> </head> <body> <script src="http://cdn.hcharts.cn/highcharts/highcharts.js"></script> <script src="http://cdn.hcharts.cn/highcharts/modules/exporting.js"></script> <div id="container" style="min-width: 410px; height: 400px; max-width: 600px; margin: 0 auto"></div> </body> </html>
3D饼状图
<!DOCTYPE HTML> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> <title>Highcharts Example</title> <script type="text/javascript" src="http://cdn.hcharts.cn/jquery/jquery-1.8.3.min.js"></script> <style type="text/css"> ${demo.css} </style> <script type="text/javascript"> $(function () { $('#container').highcharts({ chart: { type: 'pie', options3d: { enabled: true, alpha: 45, beta: 0 } }, title: { text: 'Browser market shares at a specific website, 2014' }, tooltip: { pointFormat: '{series.name}: <b>{point.percentage:.1f}%</b>' }, plotOptions: { pie: { allowPointSelect: true, cursor: 'pointer', depth: 35, dataLabels: { enabled: true, format: '<b>{point.name}</b>: {point.y} ' }, showInLegend: true } }, series: [{ type: 'pie', name: 'Browser share', data: [ ['Firefox', 10], ['IE', 10], { name: 'Chrome', y: 10, sliced: true, selected: true }, ['Safari', 59], ['Opera', 10], ] }] }); }); </script> </head> <body> <script src="http://cdn.hcharts.cn/highcharts/highcharts.js"></script> <script src="http://cdn.hcharts.cn/highcharts/highcharts-3d.js"></script> <script src="http://cdn.hcharts.cn/highcharts/modules/exporting.js"></script> <div id="container" style="height: 400px"></div> </body> </html>
浙公网安备 33010602011771号