echarts 使用之柱状图
上篇已经说过echarts 简单用法,这里直接上代码
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>ECharts</title> <!-- 引入 echarts.js --> <script src="echarts.min.js"></script> </head> <body> <!-- 为ECharts准备一个具备大小(宽高)的Dom --> <div id="main" style="width: 600px;height:400px;"></div> <script type="text/javascript"> // 基于准备好的dom,初始化echarts实例 var Chart1 = echarts.init(document.getElementById('main')); createChart1(); window.onresize = function(){ Chart1.resize(); }; function createChart1(){ option = { color: ['#3398DB'], tooltip: { trigger: 'axis', axisPointer: { // 坐标轴指示器,坐标轴触发有效 type: 'shadow' // 默认为直线,可选为:'line' | 'shadow' } }, grid: { left: '3%', right: '4%', bottom: '8%', containLabel: true }, xAxis: [ { show:false, type: 'category', data: ['羊毛衫', '裤子', '高跟鞋', '袜子'], axisTick: { alignWithLabel: true } } ], yAxis: { show:false, type: 'value', splitLine:{ show:false } }, series: [ { name: '', type: 'bar', itemStyle: { normal: { color: function(params) { var colorList = [ '#249cf9','#fdb628','#67e0e3','#eb6f49','#27727B', '#FE8463','#9BCA63','#FAD860','#F3A43B','#60C0DD', '#D7504B','#C6E579','#F4E001','#F0805A','#26C0C0' ]; return colorList[params.dataIndex] }, //以下为是否显示,显示位置和显示格式的设置了 label: { show: true, color:'#fff', position: 'bottom', // formatter: '{b}\n{c}' formatter: '{b}' } } }, //设置柱的宽度,要是数据太少,柱子太宽不美观~ barWidth:35, data: [10, 52, 80, 30] } ] }; Chart1.setOption(option); }; </script> </body> </html>
效果图:(容易背景色是自己定义的css)
注:转载请注明出处:https://www.cnblogs.com/Yjjhn/p/14185868.html
有bug请留言评论区