SQL 和 Google Charts - 给定一系列日期,缩放日期范围
我正在使用 Google Charts 创建一些图表,效果很好。我遇到的唯一问题是当我的日期范围很大时。我的 X 轴显示一系列日期。 1 到 2 周就可以了(仅限工作日,所以我要么有 5 个或 10 个日期),但是当我开始进入月份范围时,所有日期都相互重叠,并且不可读。理想情况下,对于超过 2 周的任何事情,我希望获得 10 个最重要的日期。例如,如果我的系列是从 6/1 - 7/15 的所有日期,我希望图表上的 X 轴显示如下内容:
6/1 | 6/5 | 6/10 | 6/15 | 6/20 | 6/25 | 6/30 | 7/5 | 7/10 | 7/15
使用 Google 图表,您必须指定一系列数据,因此我不能只提供开始和结束日期并使其适当缩放。仅供参考 - 我正在使用 SQL Server 存储过程来获取数据,因此我希望能够计算数据库端的日期。
I'm using Google Charts to create some graphs and it's working well. The only problem I'm having is when I have a large date range. My X axis displays the series of dates. It's fine for 1 and 2 weeks (only weekdays, so I either have 5 or 10 dates) however when I start to get up into the month(s) range, all the dates overlap one another and it's unreadable. Ideally, for anything over 2 weeks, I'd like to get the 10 most significant dates. So for example, if my series is all the dates from 6/1 - 7/15, I'd like the X axis on the graph to display something like:
6/1 | 6/5 | 6/10 | 6/15 | 6/20 | 6/25 | 6/30 | 7/5 | 7/10 | 7/15
With Google Charts, you have to specify your series of data, so I can't just provide a start and end date and have it scale appropriately. FYI - I'm using a SQL Server stored proc to obtain my data so I'd like to be able to calculate the dates on the database side.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
好的,我理解您的要求,这是一段代码,它将形成一个用“;”分隔的字符串。您可以从 SQL Server SP 返回它!
@dt1 和 @dt2 是开始日期和结束日期,您可以将其替换为本地变量。 @outText 是带有值的字符串。
如果您有任何疑问或者您希望将其作为函数/过程,请告诉我!
Ok I understand your requirement and here is a piece of code which will form a String separated by ";" which you can return from the SQL Server SP!
@dt1 and @dt2 are the start and end dates, which you can replace with your local variables. @outText is the string with values.
Let me know if you have any questions or you want this as a function/procedure!