jqPlot无法渲染

时间:2014-01-17 06:27:32

标签: jquery jqplot

我从官方网站逐字逐句地复制并粘贴了jqPlot代码,我让它在ajax调用中工作。 现在,当我使用通过我的ajax调用收到的数据时,我无法再使其正确呈现....

从AJAX传回的文字字符串:

[["2014/01/16 12:00:00 AM","215"],["2014/01/14 12:00:00 AM","225"],["2014/01/13 12:00:00 AM","219"],["2014/01/12 12:00:00 AM","218"],["2014/01/11 12:00:00 AM","220"]]

我的ajax成功电话:

success: function (data) {
                    alert(data)

                    var plot2 = $.jqplot('weightChart', [data], {
                        title: 'Customized Date Axis',
                        gridPadding: { right: 35 },
                        axes: {
                            xaxis: {
                                renderer: $.jqplot.DateAxisRenderer,
                                tickOptions: { formatString: '%b %#d, %y' },
                                min: 'May 30, 2013',
                                tickInterval: '1 month'
                            }
                        },
                        series: [{ lineWidth: 4, markerOptions: { style: 'square' } }]
                    });
                }

不确定问题是什么。谢谢大家

编辑:

我刚创建了一个硬编码数组,并在我的jqplot调用中使用它,并且它有效。但是,通过ajax调用的数据不起作用。

有什么建议吗?

1 个答案:

答案 0 :(得分:1)

我已经尝试过您的代码,但它确实有效。 奇怪的是,您使用的是涵盖一周时间的数据 在约为6个月的x轴范围内!您的数据从2014年1月开始,但是您 将最小值设置为2013年5月。 此外,这些值都在220左右,在jqplot图表中 并不总是自动缩放效果很好(通常在使用日期格式时)。

所以我做了一些改变:

xaxis: {
    renderer: $.jqplot.DateAxisRenderer,
    tickOptions: { formatString: '%b %#d, %y' },
    //min: 'May 30, 2013',
    min: 'Dec 30, 2013',
    tickInterval: '1 week'
},
yaxis: {
    min: 0,
    max: 300        
}

我希望这可以帮助您处理数据。结果如下图所示。 enter image description here

相关问题