简体   繁体   English

jqPlot不渲染

[英]jqPlot not rendering

I copy-and-pasted jqPlot code from the official website word for word and I got it to work inside an ajax call. 我从官方网站逐字复制并粘贴了jqPlot代码,并在ajax调用中使用了它。 Now, when I use data I received via my ajax call, I can't get it to render correctly anymore.... 现在,当我使用通过ajax调用接收到的数据时,无法再正确呈现它了。

Literal string being passed back from 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"]]

My ajax success call: 我的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' } }]
                    });
                }

Not sure what the problem is. 不确定是什么问题。 Thanks all 谢谢大家

EDIT: 编辑:

I just created aa hardcoded array and used that in my jqplot call, and it worked. 我刚刚创建了一个硬编码数组,并在我的jqplot调用中使用了它,并且它起作用了。 However, the data coming through the ajax call did not work. 但是,通过ajax调用获得的数据无效。

Any suggestions? 有什么建议么?

i've tried your code, and it works. 我已经尝试过您的代码,并且可以正常工作。 The strange thing is that you are using data which covers a period of a week in a range on the x-axis of about 6 months! 奇怪的是,您使用的数据涵盖了一周的一段时间,在大约6个月的x轴范围内! Your data starts from Jan 2014 but you set the min value to May 2013. Furthermore, the values are all around 220 values and in the jqplot chart not always the autoscale works well (often when you are using a date format). 您的数据从2014年1月开始,但您将最小值设置为2013年5月。此外,这些值全都在220个值左右,并且在jqplot图表中,自动缩放并非总是能正常工作(通常在使用日期格式时)。

So i made some changes: 所以我做了一些改变:

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        
}

and i hope this could help you with handling your data. 我希望这可以帮助您处理数据。 The following figure is the result. 下图是结果。 在此处输入图片说明

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM