为什么jQPlot dateAxisRenderer不正确?

时间:2022-09-15 10:53:40

i would like to use the jQPlot and will render an axis as a series of date values - the raw package of jQPlot can be font here:

我想使用jQPlot并将一个轴呈现为一系列日期值——jQPlot的原始包可以在这里使用字体:

http://www.jqplot.com/

http://www.jqplot.com/

http://www.jqplot.com/docs/files/plugins/jqplot-dateAxisRenderer-js.html

http://www.jqplot.com/docs/files/plugins/jqplot-dateAxisRenderer-js.html

The Problem is this:

问题是这样的:

a) xaxis don't start at the left side and also it will show values that i don't want to see

a) xaxis可不能从左边开始,它还会显示我不想看到的值

b) just the same problem on the right with more numbers that dont need

b)右边也是同样的问题,有更多不需要的数字

c) i would like to have all days on the xaxis 1 2 3 4 5 ... not 31 3 6 9 ...

c)我想在xaxis 1号、2号、3号、4号…不是31 3 6 9…

d) is it possible to set a kind of offset to the bottom (just a little bit ...)

d)是否可以在底部设置一种偏移量(稍微…)

Screenshot: 为什么jQPlot dateAxisRenderer不正确?

截图:

My Code:

我的代码:

$.jqplot('chartdiv', [
    [
        ['2012-08-01', 0],
        ['2012-08-02', 0],
        ['2012-08-03', 0],
        ['2012-08-04', 0],
        ['2012-08-05', 0],
        ['2012-08-06', 0],
        ['2012-08-07', 1],
        ['2012-08-08', 0],
        ['2012-08-09', 6],
        ['2012-08-10', 0],
        ['2012-08-11', 0],
        ['2012-08-12', 0],
        ['2012-08-13', 0],
        ['2012-08-14', 0],
        ['2012-08-15', 0],
        ['2012-08-16', 0],
        ['2012-08-17', 0],
        ['2012-08-18', 0],
        ['2012-08-19', 0],
        ['2012-08-20', 0],
        ['2012-08-21', 0],
        ['2012-08-22', 0],
        ['2012-08-23', 0],
        ['2012-08-24', 0],
        ['2012-08-25', 0],
        ['2012-08-26', 0],
        ['2012-08-27', 0],
        ['2012-08-28', 0],
        ['2012-08-29', 0],
        ['2012-08-30', 0],
        ['2012-08-31', 0]
    ]
], {
    title: 'Downloadstatistik',
    axes: {
        xaxis: {
            renderer: $.jqplot.DateAxisRenderer,
            tickOptions: {
                formatString: '%#d',
                tickInterval: '1 month'
            },
            pad: 1.0
        },
        yaxis: {
            tickOptions: {
                formatString: '%.0f'
            },
            min: 0
        }
    }
});

1 个解决方案

#1


10  

To start, you should try to set your tickInterval to "1 day" :)

首先,您应该尝试将tickInterval设置为“1天”:

After this, the trick is to set your xaxis min and max according to first and last values of your dates array.

在此之后,诀窍是根据日期数组的第一个和最后一个值设置xaxis min和max。

Here's an example :

这里有一个例子:

var timeline = [[
    ['2012-08-01', 0], ['2012-08-02', 0], ['2012-08-03', 0],
    ['2012-08-04', 0], ['2012-08-05', 0], ['2012-08-06', 0],
    ['2012-08-07', 1], ['2012-08-08', 0], ['2012-08-09', 6],
    ['2012-08-10', 0], ['2012-08-11', 0], ['2012-08-12', 0],
    ['2012-08-13', 0], ['2012-08-14', 0], ['2012-08-15', 0],
    ['2012-08-16', 0], ['2012-08-17', 0], ['2012-08-18', 0],
    ['2012-08-19', 0], ['2012-08-20', 0], ['2012-08-21', 0],
    ['2012-08-22', 0], ['2012-08-23', 0], ['2012-08-24', 0],
    ['2012-08-25', 0], ['2012-08-26', 0], ['2012-08-27', 0],
    ['2012-08-28', 0], ['2012-08-29', 0], ['2012-08-30', 0],
    ['2012-08-31', 0]
]];
var plot = $.jqplot('chartdiv', timeline, {
    title: 'Downloadstatistik',
    axes: {
        xaxis: {
            renderer: $.jqplot.DateAxisRenderer,
            tickOptions: { formatString: '%#d' },
            tickInterval: '1 day',
            min: timeline[0][0][0],
            max: timeline[0][timeline[0].length-1][0]
        },
        yaxis: {
            tickOptions: { formatString: '%.0f' },
            min: 0
        }
    }
});

Also I think no pad is needed.

而且我认为不需要pad。

Edit (new jsFiddle added):

编辑(新jsFiddle添加):

You can test this sample code here : http://jsfiddle.net/JhHPz/4/

您可以在这里测试这个示例代码:http://jsfiddle.net/JhHPz/4/。

#1


10  

To start, you should try to set your tickInterval to "1 day" :)

首先,您应该尝试将tickInterval设置为“1天”:

After this, the trick is to set your xaxis min and max according to first and last values of your dates array.

在此之后,诀窍是根据日期数组的第一个和最后一个值设置xaxis min和max。

Here's an example :

这里有一个例子:

var timeline = [[
    ['2012-08-01', 0], ['2012-08-02', 0], ['2012-08-03', 0],
    ['2012-08-04', 0], ['2012-08-05', 0], ['2012-08-06', 0],
    ['2012-08-07', 1], ['2012-08-08', 0], ['2012-08-09', 6],
    ['2012-08-10', 0], ['2012-08-11', 0], ['2012-08-12', 0],
    ['2012-08-13', 0], ['2012-08-14', 0], ['2012-08-15', 0],
    ['2012-08-16', 0], ['2012-08-17', 0], ['2012-08-18', 0],
    ['2012-08-19', 0], ['2012-08-20', 0], ['2012-08-21', 0],
    ['2012-08-22', 0], ['2012-08-23', 0], ['2012-08-24', 0],
    ['2012-08-25', 0], ['2012-08-26', 0], ['2012-08-27', 0],
    ['2012-08-28', 0], ['2012-08-29', 0], ['2012-08-30', 0],
    ['2012-08-31', 0]
]];
var plot = $.jqplot('chartdiv', timeline, {
    title: 'Downloadstatistik',
    axes: {
        xaxis: {
            renderer: $.jqplot.DateAxisRenderer,
            tickOptions: { formatString: '%#d' },
            tickInterval: '1 day',
            min: timeline[0][0][0],
            max: timeline[0][timeline[0].length-1][0]
        },
        yaxis: {
            tickOptions: { formatString: '%.0f' },
            min: 0
        }
    }
});

Also I think no pad is needed.

而且我认为不需要pad。

Edit (new jsFiddle added):

编辑(新jsFiddle添加):

You can test this sample code here : http://jsfiddle.net/JhHPz/4/

您可以在这里测试这个示例代码:http://jsfiddle.net/JhHPz/4/。