使用每周标签设置 DateTimeAxis 在一周中的任意一天设置刻度

发布于 2024-09-11 10:29:32 字数 610 浏览 4 评论 0原文

我使用 CartesianChart 和 DateTimeAxis 在 Flex 应用程序中显示每周数据。当我在 DateTimeAxis 上设置 dataUnits="weeks" 和 labelUnits="weeks" 时,它会自动将每个主要刻度放在星期日。不过,我想为用户提供从周日或周一开始一周的选项。我怎样才能要求 DateTimeAxis 将主要刻度放在星期一(或一周中的其他一天)?

例如,如果用户正在查看一周内某项的总和,并请求周从星期日开始,则系列数据将如下所示:

x: Date(July 11, 2010)  y: 25
x: Date(July 18, 2010)  y: 30
x: Date(July 25, 2010)  y: 32
etc.

如果周从星期一开始,则系列数据将如下所示

x: Date(July 12, 2010)  y: 22
x: Date(July 19, 2010)  y: 33
x: Date(July 26, 2010)  y: 29
etc.

:第二个数据集,主要刻度线仍在 7 月 11 日、7 月 18 日、7 月 25 日等,但条形图稍微偏离主要刻度线的中心。

谢谢!

I'm using a CartesianChart with a DateTimeAxis to display weekly data in a Flex application. When I set dataUnits="weeks" and labelUnits="weeks" on the DateTimeAxis, it automatically places each major tick on a Sunday. However, I would like to provide users with the option of beginning the week on a Sunday or a Monday. How can I ask the DateTimeAxis to instead place the major ticks on a Monday (or some other day of week)?

For example, if the user is looking at total sum of something over the week, and requests that weeks start on a Sunday, the Series data would look like:

x: Date(July 11, 2010)  y: 25
x: Date(July 18, 2010)  y: 30
x: Date(July 25, 2010)  y: 32
etc.

If the weeks start on a Monday, the Series data would instead look like:

x: Date(July 12, 2010)  y: 22
x: Date(July 19, 2010)  y: 33
x: Date(July 26, 2010)  y: 29
etc.

With the second data set, the major ticks are still on July 11, July 18, July 25, etc. but the bars are slightly shifted off-center from the major ticks.

Thanks!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

忆依然 2024-09-18 10:29:32

我查看了 DateTimeAxis 类的代码,我几乎可以肯定你不能做你想做的事。如果“alignLabelsToUnits”属性设置为 true(默认),则通过将系列数据日期四舍五入到适当的单位来创建标签。在您的情况(周)中,它看起来像这样:

case "weeks":
    d[hoursP] = 0;
    d[minutesP] = 0;
    d[secondsP] = 0;
    d[millisecondsP] = 0;
    if (d[dayP] != 0)
        d[dateP] = d[dateP] + (7 - d[dayP]);
    break;

正如您所看到的,它检查处理的日期是否是一周的第一天(硬编码0),如果不是,则更改为这样。
为了实现您所寻求的行为,您可能必须重写用于标签创建的函数,并编写另一个用于日期舍入的函数,因为默认舍入函数被声明为私有。

I looked at the code of DateTimeAxis class and I'm almost sure you can't do what you want. If "alignLabelsToUnits" property is set to true (default) then labels are created by rounding Series data dates to appropriate units. In your case (weeks) it looks like this:

case "weeks":
    d[hoursP] = 0;
    d[minutesP] = 0;
    d[secondsP] = 0;
    d[millisecondsP] = 0;
    if (d[dayP] != 0)
        d[dateP] = d[dateP] + (7 - d[dayP]);
    break;

So as you can see, it checks if processed date is first day of the week (hard-coded 0), and if it is not, it's changed to be such.
To achieve the behavior you seek, you'd probably have to override function for label creation and write another one for date rounding, as the default rounding function is declared private.

淡笑忘祈一世凡恋 2024-09-18 10:29:32

即使您指定了周,DateTimeAxis 仍可能使用新创建的日期对象的小时和分钟值。您可以设置日期格式以将其设置为零。看看http://www.munkiihouse.com/?p=69,提及在 DateTimeAxis 标记中设置 displayLocalTime=”true”。让我们知道它是否有效

Even though you specify weeks, DateTimeAxis may still be using the hours and minutes values of the newly created date objects. You can format the date to set these to zero. Have a look at http://www.munkiihouse.com/?p=69, mention setting displayLocalTime=”true” in DateTimeAxis tag. Let us know if it works man

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文