I am currently working on a simple timetable project with Google Charts, although I have encountered a problem that it seems I don't know a way to fix.
I want the dates to change through user input. I've tried something but I don't know how to continue.
Here is the jsfiddle link:
I tried adding form and variables but when I put the variable in the date it doesn't recognize it.
Here is the code:
google.charts.load("current", {
packages: ["timeline"]
});
G2start = parseInt(document.getElementById('G2startvar').value);
G2end = parseInt(document.getElementById('G2endvar').value);
G3start = parseInt(document.getElementById('G3startvar').value);
G3end = parseInt(document.getElementById('G3endvar').value);
google.charts.setOnLoadCallback(drawChart);
function drawChart() {
var container = document.getElementById('timechart');
//1st is (G4.5), 2nd is (G2), 3rd is, (G3), 4th is (G3.1), 5th is (G3.2)
var options = {
colors: ['#113477', '#C0C0C0', '#adc6e5', '#72aae4', '#518cc2', '#4A7FB0'],
timeline: {
rowLabelStyle: {
fontName: 'Arial',
fontSize: 25,
color: '#0000'
},
barLabelStyle: {
fontName: 'Times New Roman',
fontSize: 32
}
},
'width': 3950,
'height': 5200,
avoidOverlappingGridLines: false
};
var chart = new google.visualization.Timeline(container);
var dataTable = new google.visualization.DataTable();
dataTable.addColumn({
type: 'string',
id: 'Position'
});
dataTable.addColumn({
type: 'string',
id: 'Name'
});
dataTable.addColumn({
type: 'date',
id: 'Start'
});
dataTable.addColumn({
type: 'date',
id: 'End'
});
dataTable.addRows([
[Date(), 'Now', new Date(), new Date()],
['Project #1', 'G2', new Date(2022, 11, 15), new Date(2022, 11, 30)],
['Project #1', 'G3', new Date(2022, 11, 30), new Date(2023, 5, 17)],
]);
chart.draw(dataTable, options);
}
h1 {
color: #3e74ab;
text-shadow: 1px 1px;
font-family: "Times New Roman", Times, serif;
text-align: center;
}
<script type="text/javascript" src="https://www.gstatic.com/charts/loader.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.6.0/jquery.min.js"></script>
<h1>Project Timetable</h1>
<body>
<p>Please input your project dates</p>
<form id="form1" onsubmit="drawChart(); return false">
<label for="G2startvar">G1 Start Date: </label><input type="date" id="G2startvar"><br>
<label for="G2endvar">G1 End Date: </label><input type="date" id="G2endvar"><br>
<label for="G3startvar">G2 Start date: </label><input type="DATE" id="G3startvar"><br>
<label for="G3endvar">G2 End Date : </label><input type="date" id="G3endvar"><br>
<button type="submit" value="Submit">Submit</button>
</form>
<div id="timechart" style="height: 1000px;"></div>