回到首页
个人中心
反馈问题
注册登录
下载APP
代码
提交代码
<!DOCTYPE html> <html lang="zh-CN"> <head> <meta charset="utf-8" /> <meta http-equiv="X-UA-Compatible" content="IE=edge" /> <meta name="viewport" content="width=device-width,initial-scale=1.0" /> <title>Echarts Example</title> </head> <body> <div id="main" style="width: 600px;height: 400px"></div> <script src="//cdn.bootcss.com/echarts/4.5.0/echarts.js"></script> <script type="text/javascript"> // 随机生成数据 function generateData(cats) { const random = (min, max) => Math.round(Math.random() * (max - min) + min); const series = [ { name: '我司', type: 'effectScatter' }, { name: '竞品1', type: 'scatter' }, { name: '竞品2', type: 'scatter' }, { name: '竞品3', type: 'scatter' }, ]; return series.map((serie) => ({ ...serie, data: cats.map((cat) => [cat, random(100, 10000)]), })); } const myChart = echarts.init(document.getElementById('main')); const cats = ['1月', '2月', '3月', '4月', '5月', '6月', '7月', '8月', '9月', '10月', '11月', '12月']; const series = generateData(cats); var option = { xAxis: { type: 'category', data: cats }, yAxis: { type: 'value' }, series: series, legend: { data: series.map((s) => s.name) }, }; myChart.setOption(option); </script> </body> </html>
运行结果