function getdata() { return { sale: [Math.random(), Math.random(), Math.random(), Math.random(), Math.random(), Math.random()], made: [Math.random(), Math.random(), Math.random(), Math.random(), Math.random(), Math.random()] }; } // 指定图表的配置项和数据 var option = { title: { text: '产销量对比图' }, tooltip: {}, legend: { data: ['销量', '产量'] }, xAxis: { data: ['衬衫', '羊毛衫', '雪纺衫', '裤子', '高跟鞋', '袜子'] }, yAxis: {}, series: [{ name: '销量', type: 'bar', data: getdata().sale, //stack:'x', //柱状堆叠 barWidth: "15%", //柱子宽度 itemStyle: { normal: { barBorderRadius: 35, //圆角 //渐变填充 color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [{ offset: 0, color: '#8bd46e' }, { offset: 1, color: '#09bcb7' }]), ////////////// }, } }, { name: '产量', type: 'bar', data: getdata().made, //stack:'x', //柱状堆叠 barWidth: "15%", itemStyle: { normal: { barBorderRadius: 35, color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [{ offset: 0, color: '#248ff7' }, { offset: 1, color: '#6851f1' }]), }, } } ], }; // 使用刚指定的配置项和数据显示图表。 myChart.setOption(option); setInterval(() => { myChart.setOption({ series: [{ data: getdata().sale, }, { data: getdata().made, } ] }); }, 1000); window.addEventListener("resize", function() { myChart.resize(); });