本文介绍了Google图表,每天的时间从8:00开始,到7:45结束的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在使用Google图表时遇到了一些麻烦.我有一个Google区域图:
I'm having some trouble with Google charts. I have a Google area chart:
<script type="text/javascript"> google.load("visualization", "1", {packages:["corechart"]}); google.setOnLoadCallback(drawChart); function drawChart() { var data = new google.visualization.DataTable(); data.addColumn('timeofday','time'); data.addColumn('number','temp'); data.addRows([ [[8,0,0],7.875], [[8,15,0],7.9399996], [[8,30,0],8.1], [[8,45,0],8.160001], [[9,0,0],8.139999], // data every quarter of an hour [[7,15,0],9.26], [[7,30,0],9.26], [[7,45,0],9.18] ]); var options = { title: 'Title', vAxis: { title: 'AvgTemp', titleTextStyle: {color: 'red'}, } hAxis: { title: 'Time', titleTextStyle: {color: 'red'}, } }; var chart = new google.visualization.AreaChart(document.getElementById('chart_div2')); chart.draw(data, options); } </script>现在,当我加载页面时,图表的hAxis开始于0:00,结束于24:00,并破坏了图表.如何使图表从8:00开始到7:45结束?
Now, when I load my page, the hAxis of the chart starts at 0:00 and ends at 24:00, and it destroys the chart. How can I make it so that the chart starts at 8:00 and ends at 7:45?
我已经尝试过使用视图窗口进行某些操作,但似乎无法使其正常工作.
I've tried some things with view window but I can't seem to make it work.
谢谢.
推荐答案答案是使用日期时间而不是一天中的某个时间,这样您就需要添加一个日期,这就是api如何知道哪个时间先到
The answer was to use a datetime instead of a time of the day, this way you need to add a date and thats how the api knows which time comes first.
像这样:
<script type="text/javascript"> google.load("visualization", "1", {packages:["corechart"]}); google.setOnLoadCallback(drawChart); function drawChart() { var data = new google.visualization.DataTable(); data.addColumn('datetime','time'); data.addColumn('number','temp'); data.addRows([ [new Date(2012,11,3,8,0,0),7.875], [new Date(2012,11,3,8,15,0),7.9399996], [new Date(2012,11,3,8,30,0),8.1], [new Date(2012,11,3,8,45,0),8.160001], [new Date(2012,11,3,9,0,0),8.139999], //new data every quarter of an hour [new Date(2012,11,4,7,0,0),9.42], [new Date(2012,11,4,7,15,0),9.26], [new Date(2012,11,4,7,30,0),9.26], [new Date(2012,11,4,7,45,0),9.18] ]); var options = { title: 'Title', vAxis: { title: 'AvgTemp', titleTextStyle: {color: 'red'}, }, hAxis: { title: 'Time', titleTextStyle: {color: 'red'}, } }; var chart = new google.visualization.AreaChart(document.getElementById('chart_div2')); chart.draw(data, options); } </script>更多推荐
Google图表,每天的时间从8:00开始,到7:45结束
发布评论