I am trying to make my charts responsive, using echarts.js. I found here that I can use the property media and query.
The problem is that I do not see any change when I change the width.
let myChart = echarts.init(document.getElementById('barchart'));
let option = {
baseOption: { // baseOption
tooltip: {
formatter: 'Hashtag {b} <br /> Tweets: {c}'
},
toolbox: {
feature: {
dataView: {},
restore: {},
saveAsImage: {},
},
left: '1%',
top:'top',
right:'auto',
bottom:'auto'
},
grid: {
left: '2%',
top: '17%',
right: 'auto',
bottom: '10%',
containLabel: true
},
xAxis: {
type: 'category',
axisTick: {
alignWithLabel: true,
interval: 0
},
axisLabel: {
interval: 0,
rotate: 45,
width: 78,
overflow: 'truncate'
},
axisPointer: {
show: true,
type: 'shadow'
},
data: hashtags
},
yAxis: {
type: 'value'
},
series: [
{
name: 'Tweet count',
type: 'bar',
data: countOfEachHashTag,
showBackground: true,
backgroundStyle: {
color: 'rgba(180, 180, 180, 0.2)'
},
label: {
show: true,
position: 'top'
},
itemStyle: {
color: 'rgb(8,72,103)'
}
}
]
},
media: [
{
query: {
maxWidth: 576
},
option: {
grid: {
left: 'auto',
top: 'auto',
right: 'auto',
bottom: 'auto',
width: '406',
height: '600',
containLabel: true
}
}
}
]
};
myChart.setOption(option);
My code seems correct, as per the example, but I do not see any change in the container’s width and height when I resize my window and the container size descreases too.
My html code for this chart is this:
<div id="barChartCollapse" class="collapse show">
<div id="barchart" style="width: auto;height:600px;">
</div>
</div>
Is something missing?
minWidth, as per the example, works, but maxWidth doesn’t. The example link that I provided specifically points that width, height, aspectRatio (height / width), each of which can add min or max as prefix. That’s very strange.