jqPlot DateAxis tickInterval不工作 [英] jqPlot DateAxis tickInterval not working

查看:223
本文介绍了jqPlot DateAxis tickInterval不工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试每月绘制一个带有单个数据点的图表。我在每个月的第一天将其发送到jqPlot作为单点:

I'm trying to draw a chart with a single datapoint each month. I'm sending this through to jqPlot as a single point on the first of each month:

$.jqplot('actualChart', [[['2011-10-01',0.296],['2011-11-01',0.682]]], {
    title: programSelection.options[programSelection.selectedIndex].text,
    axes: {
        xaxis: {
            renderer: $.jqplot.DateAxisRenderer,
            rendererOptions: { tickRenderer: $.jqplot.CanvasAxisTickRenderer },
            tickOptions: { formatString: '%b' }
        }
    }
}

我是使用Ajax加载图表数据。有些数据集比其他数据集有更多的数据点 - 在上面的示例中只有2个点,x轴刻度('%b'表示只显示为10月和11月)沿着轴,但经常,例如Sep ... Oct ... Oct ... Oct ... Oct ... Nov - 沿着显示的线的常规点。我只想在10月初的一个刻度线和另一个在N的开头ov。

I'm loading the chart data using Ajax. Some datasets have more points of data than others - in the example above with only 2 points, the x-axis ticks (which '%b' means just appear as Oct and Nov) are rendered automatically along the axis, but too often, e.g. Sep...Oct...Oct...Oct...Oct...Nov - at regular points along the line that is shown. I just want a single tick at the start of Oct and another at the start of Nov.

我花了很多时间搜索,似乎为此做了tickInterval,但添加了

I have spent a lot of time searching and it seems tickInterval is made for this, but adding

tickInterval: '1 month'

只是制作x-轴,数据点和线消失 - 这是我所指的破碎功能!指定任何其他区间,例如

just makes the x-axis, datapoints and line disappear - this is the broken functionality I'm referring to! Specifying any other interval e.g.

tickInterval: '2 days'

也打破它。

解决方法是手动提供滴答,例如

A workaround is to provide the ticks manually, e.g.

ticks: ['2011-10-01','2011-11-01']

这个确实将刻度线放在正确的位置,但是

This does put the ticks in the right place, but

a)是一个不应该被要求的麻烦,并且

a) is a hassle that should not be required, and

b)在图的数据点的任何一端丢失了漂亮的填充,因此两端的点出现在边缘上图表。当然,除非添加任何一方的手动勾选,但在上面的10月至11月示例中,我不希望在任何一方提供整月,因为有趣的数据仅占用图的中间三分之一。

b) loses the nice padding at either end of the graph's datapoints, so the points at either end appear on the edges of the graph. Unless manual ticks either side are added, of course, but in the Oct-Nov example above I don't want to provide a whole month on either side because then the interesting data takes up only the middle third of the graph.

任何人都可以帮我这个吗?在此先感谢。

Can anyone help me with this? Thanks in advance.

编辑 - 找到解决方案:为轴提供 min 属性似乎确实已修复这(无论出于什么原因...... bug?),所以除非有人有更好的想法,否则我会这样做!

EDIT - found a solution: Providing a min attribute for the axis does appear to fix this (for whatever reason... bug?), so unless anyone has any better ideas I'll do this!

推荐答案

我找到了解决方案!
您需要将tickinterval指定为javascript时间戳。
所以假设你想要1个小时。这将是1000 * 60 * 60 = 3600000(javascript时间戳以毫秒为单位)。

I found a solution! You need to specify the tickinterval as a javascript timestamp. So lets say you want 1 hour. That would be 1000*60*60 = 3600000 (javascript timestamps are in milliseconds).

所以你会写:tickInterval:'3600000',

So you would write: tickInterval:'3600000',

在这里工作。

这篇关于jqPlot DateAxis tickInterval不工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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