console
let chartDom = document.querySelector('#myDom');
const wi = 786;
const he = 704;
let scale = 0;
if (wi > (he * 5 / 3)) {
scale = Number((1 / (wi / 500)).toFixed(2));
} else {
scale = Number((1 / (he / 300)).toFixed(2));
}
chartDom.style.width = `${wi}px`;
chartDom.style.height = `${he}px`;
chartDom.style.transform = `scale(${scale},${scale})`;
chartDom.style.top = `${-(chartDom.getBoundingClientRect().top) + 10}px`;
chartDom.style.left = `${-(chartDom.getBoundingClientRect().left) + 10}px`;
const myChart = echarts.init(chartDom);
let option;
option = {
xAxis: {
data: ['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun']
},
yAxis: {},
series: [
{
type: 'bar',
data: [23, 24, 18, 25, 27, 28, 25]
}
]
};
option && myChart.setOption(option);
<script src="https://cdn.staticfile.org/echarts/5.3.2/echarts.min.js"></script>
<div id="myDom"></div>
body{
position: relative;
width: 500px;
height: 300px;
}
#myDom {
position: absolute;
width: 500px;
height: 300px;
border: #c8c8c8 solid 2px;
background-image:
background-repeat: no-repeat;
background-size: 100% 100%;
}