I have a webpage with a left side menu and a canvas chart.
The left side menu takes up the first 155 pixels of the width.
The chart is then set to a width of 100% (100 % of what is left after the left menu have occupied the first 155 pixels)
The problem is that when I close the left menu, the chart is not refreshed, and now it does not take up 100% of the available window width, I can only get it to refresh when resizing the window manually with the mouse.
I use the following code:-
<html>
<title>Test1</title>
<link rel="stylesheet" href="https://www.w3schools.com/w3css/4/w3.css">
<body>
<div class="w3-sidebar w3-light-grey w3-card-4 w3-animate-left" style="width:155px; line-height:16px;" id="mySidebar">
<div class="w3-bar w3-dark-grey">
<span class="w3-bar-item w3-padding-16">Menu</span>
<button onclick="w3_close_left_menu()" class="w3-bar-item w3-button w3-right w3-padding-16" title="close Sidebar">×</button>
</div>
<div class="w3-bar-block">
<a class="w3-bar-item w3-button w3-border-bottom" href="regn.html">Test</a>
</div>
</div>
<div id="main" style="margin-left:155px">
<div class="w3-container w3-display-container">
<span title="open Sidebar" style="display:none" id="openNav" class="w3-button w3-transparent w3-display-topleft w3-xlarge" onclick="w3_open_left_menu()">☰</span>
</div>
<div style="padding-top:20px; padding-left:40px; width:100%;">
DivFirst
</div>
<div style="padding-top:5px; padding-left:10px; padding-bottom:10px; width:98%; background-color: #11ffcc;">
DivSecond
<script type="text/javascript">
window.onload = function() {;
var chart0 = new CanvasJS.Chart("chartContainer0", {
legend: {
fontSize: 4
},
zoomEnabled: true,
toolTip: {
content: "{y} grader <br>{x}",
shared: false
},
axisX: {
gridColor: "Black",
gridThickness: 1,
interval: 1,
intervalType: "day",
interlacedColor: "#FCFCFF",
valueFormatString: "HH:mm - DD MMM",
labelFontSize: 14,
labelFontColor: "black"
},
theme: "theme1",
axisY: {
includeZero: false,
labelFontSize: 14,
labelFontColor: "black"
},
data: [{
type: "line",
lineThickness: 2,
showInLegend: true,
markerType: "square",
color: "#F08080",
xValueFormatString: "HH:mm - DD MMM YYYY",
legendText: "Inde temp",
dataPoints: [{
x: new Date(2017, 10, 3, 6, 30),
y: 22.15
}, {
x: new Date(2017, 10, 3, 7, 00),
y: 22.10
}, {
x: new Date(2017, 10, 3, 7, 30),
y: 21.89
}, ]
}, ],
legend: {
cursor: "pointer"
}
});
chart0.render();
}
</script>
<script type="text/javascript" src="https://canvasjs.com/assets/script/canvasjs.min.js"></script>
<div id="chartContainer0" style="height: 400px; width: 99%;"></div>
</div>
</div>
<script>
function w3_open_left_menu() {
document.getElementById("main").style.marginLeft = "155px";
document.getElementById("mySidebar").style.width = "155px";
document.getElementById("mySidebar").style.display = "block";
document.getElementById("openNav").style.display = 'none';
}
function w3_close_left_menu() {
document.getElementById("main").style.marginLeft = "0";
document.getElementById("mySidebar").style.display = "none";
document.getElementById("openNav").style.display = "inline-block";
document.getElementById("chartContainer0").reload(false);
}
</script>
</body>
</html>
In the function 'w3_close_left_menu
' I have tried to add the line:-
document.getElementById("chartContainer0").reload(false);
But that does not force the canvas to be refreshed