1. 程式人生 > >將echarts圖調成響應式的程式碼

將echarts圖調成響應式的程式碼

<!doctype html> <html lang="us"> <head> <meta charset="utf-8"><title></title><script src="echarts.min.js"></script> </head> <body> <div id="main" style="width: 600px;height:400px;"></div> </body> </html> <script src="jquery.js"></script> <script> var myChart = document.getElementById('main');
//自適應寬高var myChartContainer = function () { myChart.style.width = window.innerWidth+'px'; myChart.style.height = window.innerHeight+'px'; }; myChartContainer(); var myChart = echarts.init(myChart); option = { title: { text: '基礎雷達圖' }, radar: { indicator: [ { name: '銷售', max: 6500}, { name: '管理', max: 16000},
{ name: '資訊科技', max: 30000}, { name: '客服', max: 38000}, { name: '研發', max: 52000}, { name: '市場', max: 25000} ], name:{ formatter:function(v){ console.log(v);return v; } }, triggerEvent:true }, series: [ { name: '預算vs開銷', type: 'radar', data : [{ value : [4300, 10000, 28000, 35000, 50000, 19000], name : '預算分配' }, { value : [5000, 14000, 28000, 31000, 42000, 21000],
name : '實際開銷' }] }]}; myChart.setOption(option); //瀏覽器大小改變時重置大小 window.onresize = function () { myChartContainer(); myChart.resize(); }; </script>