Javascript examples for Google Chart:Line Chart
Move Date/Year to the Top of the Chart in Google Charts Timeline
<html> <head> <meta name="viewport" content="width=device-width, initial-scale=1"> </head> <body> <script type="text/javascript" src="https://www.gstatic.com/charts/loader.js"></script> <div id="chart_div"></div> <script type="text/javascript"> google.charts.load('current', {'packages':['timeline']}); google.charts.setOnLoadCallback(drawChart); function drawChart() {//from ww w . j av a2 s . com var data = new google.visualization.DataTable({ cols: [ {id: 'team', label: 'Team', type: 'string'}, {id: 'start', label: 'Season Start Date', type: 'date'}, {id: 'end', label: 'Season End Date', type: 'date'} ], rows: [ {c: [{v: 'Baltimore Ravens'}, {v: 'Date(2000, 8, 5)'}, {v: 'Date(2001, 1, 5)'}]}, {c: [{v: 'New England Patriots'}, {v: 'Date(2001, 8, 5)'}, {v: 'Date(2002, 1, 5)'}]}, {c: [{v: 'Tampa Bay Buccaneers'}, {v: 'Date(2002, 8, 5)'}, {v: 'Date(2003, 1, 5)'}]}, {c: [{v: 'New England Patriots'}, {v: 'Date(2003, 8, 5)'}, {v: 'Date(2004, 1, 5)'}]}, {c: [{v: 'New England Patriots'}, {v: 'Date(2004, 8, 5)'}, {v: 'Date(2005, 1, 5)'}]}, {c: [{v: 'Pittsburgh Steelers'}, {v: 'Date(2005, 8, 5)'}, {v: 'Date(2006, 1, 5)'}]}, {c: [{v: 'Indianapolis Colts'}, {v: 'Date(2006, 8, 5)'}, {v: 'Date(2007, 1, 5)'}]}, {c: [{v: 'New York Giants'}, {v: 'Date(2007, 8, 5)'}, {v: 'Date(2008, 1, 5)'}]}, {c: [{v: 'Pittsburgh Steelers'}, {v: 'Date(2008, 8, 5)'}, {v: 'Date(2009, 1, 5)'}]}, {c: [{v: 'New Orleans Saints'}, {v: 'Date(2009, 8, 5)'}, {v: 'Date(2010, 1, 5)'}]}, {c: [{v: 'Green Bay Packers'}, {v: 'Date(2010, 8, 5)'}, {v: 'Date(2011, 1, 5)'}]}, {c: [{v: 'New York Giants'}, {v: 'Date(2011, 8, 5)'}, {v: 'Date(2012, 1, 5)'}]}, {c: [{v: 'Baltimore Ravens'}, {v: 'Date(2012, 8, 5)'}, {v: 'Date(2013, 1, 5)'}]}, {c: [{v: 'Seattle Seahawks'}, {v: 'Date(2013, 8, 5)'}, {v: 'Date(2014, 1, 5)'}]} ] }); var options = { height: 450, timeline: { groupByRowLabel: true } }; var chart = new google.visualization.Timeline(document.getElementById('chart_div')); google.visualization.events.addListener(chart, 'ready', afterDraw); chart.draw(data, options); } function afterDraw() { var g = document.getElementsByTagName("svg")[0].getElementsByTagName("g")[1]; document.getElementsByTagName("svg")[0].parentNode.style.top = '40px'; document.getElementsByTagName("svg")[0].style.overflow = 'visible'; var height = Number(g.getElementsByTagName("text")[0].getAttribute('y')) + 15; g.setAttribute('transform','translate(0,-'+height+')'); g = null; } </script> </body> </html>