先上图
最近要求实现一个数据统计的界面,就是那种很多个统计图在一个界面显示,并且要做出十分炫酷的效果,必然会用到了渐变风格的设置属性。写一个小的demo:
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>柱状图渐变</title> <!-- 引入 echarts.js --> <script src="https://cdn.bootcss.com/echarts/4.2.1-rc1/echarts.min.js" type="text/javascript"></script> <script src="http://code.jquery.com/jquery-1.8.0.min.js"></script> </head> <body> <!-- 为ECharts准备一个具备大小(宽高)的Dom --> <div id="main" style="width: 600px;height:400px;"></div> <script type="text/javascript"> // 基于准备好的dom,初始化echarts实例 var myChart = echarts.init(document.getElementById('main')); // 指定图表的配置项和数据 myChart.setOption({ title: { text: '柱状图渐变' }, tooltip: {}, legend: { data: ['销量'] }, xAxis: { data: ["1", "2", "3", "4","1", "2", "3", "4", "3"] }, yAxis: {}, series: [{ name: '销量', type: 'bar', itemStyle: { normal: { color: new echarts.graphic.LinearGradient(0, 1, 0, 0, [{ offset: 0, color: "#1268f3" // 0% 处的颜色 }, { offset: 0.6, color: "#08a4fa" // 60% 处的颜色 }, { offset: 1, color: "#01ccfe" // 100% 处的颜色 }], false) } }, data: ["1", "2", "3", "4","1", "2", "3", "4", "3"] }] }); </script> </body> </html>