Google图表,每天的时间从8:00开始,到7:45结束

编程入门 行业动态 更新时间:2024-10-19 18:20:24
本文介绍了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结束

本文发布于:2023-11-27 04:11:51,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1636540.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:图表   结束   时间   Google

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!