如何使用X轴日期与谷歌图表API? [英] How to use dates in X-axis with Google chart API?

查看:102
本文介绍了如何使用X轴日期与谷歌图表API?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有一种方法来绘制与谷歌图表API的图表,使X轴值是一个月中的天?

我有没有设置在相同的频率的数据点。例如:

 日期 - 值
1/1/2009 - 100
1/5/2009 - 150
2009年1月6日 - 165
2009年1月13日 - 200
二零零九年一月二十零日 - 350
二零零九年一月三十零日 - 500

我想打一个图表,将每个数据点用了一个月期间基于时间的相对距离分开。这可以用Excel做,但我怎么能计算并与谷歌的图表显示呢?

类似于谷歌图表或免费的图书馆其他免费的解决方案,可以在ASP.NET中使用,也欢迎。


解决方案

  

更新这是现在直接使用先进的图形支持的图表API中的图表注释功能 - 的 https://developers.google.com/chart/interactive/docs/gallery/annotationchart


我这样做对我的翻版数据库统计图表(即使日期竟然是均匀地隔开,因此它不完全证明它在做此)。

首先,你希望得到您的整个时间段后,这将是类似于图表的总宽度。要做到这一点,我们减去从最新的最早日期。我preFER使用Unix的时代时间戳,因为它们是整数,易于以这种方式来比较,但你可以很容易地计算出的秒数,等等。

现在,通过你的数据环路。每个日期我们想要的百分的全过程中,该日期是从一开始(即,最早日期是0,最新的是100)。对于每一个日期,你首先要在数据集中的最早日期计算present日的的距离。从本质上讲,多远,我们从一开始。因此,减去从present日期的最早日期。然后,找到了百分,我们把present日总时间段距离,再乘以100,并截断或圆形的小数给我们的整体的 x坐标

和它就是这么简单!您的x值范围从0(图表的左侧)到100(右侧),并且每个数据点将位于在距离从开始各自的它的真实时间距离

如果您有任何疑问,请随时问!如果需要的话我可以张贴04-0030-03 code或PHP。

Is there a way to plot a chart with Google chart API so that the X-axis values are days in a month?

I have data points that are not provided with the same frequency. For example:

Date - Value
1/1/2009 - 100
1/5/2009 - 150
1/6/2009 - 165
1/13/2009 - 200
1/20/2009 - 350
1/30/2009 - 500

I want to make a chart that will separate each data point with the relative distance based on time during a month. This can be done with Excel, but how can I calculate and display it with Google chart?

Other free solutions similar to Google chart or a free library that can be used with ASP.NET are also welcome.

解决方案

UPDATE This is now supported directly in the Chart API using the advanced graphs "annotated chart" feature - https://developers.google.com/chart/interactive/docs/gallery/annotationchart

I have done this on my ReHash Database Statistics chart (even though the dates turned out to be evenly spaced, so it doesn't exactly demonstrate that it's doing this).

First, you want to get your overall time period, which will be analogous to the overall width of your chart. To do this we subtract the earliest date from the latest. I prefer to use Unix-epoch timestamps as they are integers and easy to compare in this way, but you could easily calculate the number of seconds, etc.

Now, loop through your data. For each date we want the percentile in the overall period that the date is from the beginning (i.e. the earliest date is 0, the latest is 100). For each date, you first want to calculate the distance of the present date from the earliest date in the data set. Essentially, "how far are we from the start". So, subtract the earliest date from the present date. Then, to find the percentile, we divide the distance of the present date by the overall time period, and then multiply by 100 and truncate or round any decimal to give our integral x-coordinate.

And it is as simple as that! Your x-values will range from 0 (the left-side of the chart) to 100 (the right side) and each data point will lie at a distance from the start respective of it's true temporal distance.

If you have any questions, feel free to ask! I can post pesudocode or PHP if desired.

这篇关于如何使用X轴日期与谷歌图表API?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆