I want to print in the google charts title the current month
var monthNames = ["January", "February", "March", "April", "May", "June",
"July", "August", "September", "October", "November", "December"
];
var d = new Date();
var month = document.write("The current month is " + monthNames[d.getMonth()]);
// Set chart options
var options = { 'title':'',
'width':400,
'height':300};
Get rid of the document.write
and just assign the desired month to a variable and use it in the title
var monthNames = ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December" ]; var d = new Date(); var month = "The current month is " + monthNames[d.getMonth()]; google.charts.load('current', {'packages':['corechart']}); google.charts.setOnLoadCallback(drawChart); function drawChart() { var data = google.visualization.arrayToDataTable([ ['Task', 'Hours per Day'], ['Work', 11], ['Eat', 2], ['Commute', 2], ['Watch TV', 2], ['Sleep', 7] ]); var options = { title: month }; var chart = new google.visualization.PieChart(document.getElementById('piechart')); chart.draw(data, options); }
<script type="text/javascript" src="https://www.gstatic.com/charts/loader.js"></script> <div id="piechart" style="width: 400px; height: 400px;"></div>
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.