什么'这是错误的自动创建图表花在网页上的时间
what's wrong with this automatic creation of charts for time spent on webpages?
!解决了
我想自动创建图表,包括用户及其在网站页面上花费的时间。
我有一个文件——"log.xml",我在其中保存用户(客户(的信息、访问的页面、日期和他们花费的时间;在我用Ajax"获得"这个Xml文件后,我想解析它,并用JqPlot创建带有值的"提取"图表。
我的问题是我不能遍历多个客户,而且它不能为单个客户构建图表。
如果我在初始化变量plot
时删除代码块,我<strong]可以通过Xml中的所有客户循环>。
请,如果有人能告诉我哪里出了问题,以及如何为所有客户创建图表。。。
以下是文件">log.xml"的代码:
<?xml version="1.0"?>
<log>
<customer id="14" name="Florin Virdol">
<page name="/mobilestore/index.php">
<date_ts on="2011-12-02" timeSpent="205"/>
</page>
<page name="/mobilestore/products_all.php">
<date_ts on="2011-12-02" timeSpent="15"/>
</page>
</customer>
<customer id="0" name="guest">
<page name="/mobilestore/services.php">
<date_ts on="2011-12-02" timeSpent="50"/>
</page>
</customer>
</log>
以下是"操作"的javascript代码:
$(document).ready(function()
{
//read from xml
$.ajax({
type: "GET",
url: "log.xml",
dataType: "xml",
success: parseXml
});
});//ready
//parse xml
function parseXml(xml) {
var i = 0;
$(xml).find("customer").each(function() {
$('<div class = "jqplot graph" id = "chart' + i + '"></div>').appendTo('#content');
var customerName = $(this).attr("name");
var line_inside = []; // declare as array
$(this).find("page").each(function() {
var pageName = $(this).attr("name");
$(this).find("date_ts").each(function() {
var timeSpent_ = $(this).attr("timeSpent");//if mai multe timespent, sa faca totalul, else singuru; timespent
line_inside.push([pageName,timeSpent_]); //do not string cat, push onto array
});
});
var line = '[' + line_inside + ']';
//--------jqplot----!!! if i remove this block, will loop through customers------------
var plot = $.jqplot('chart' + i, [line_inside],
{
title: customerName,
series:[{renderer:$.jqplot.BarRenderer}],
axes: {
xaxis: {
renderer: $.jqplot.CategoryAxisRenderer,
label: 'Web Page',
labelRenderer: $.jqplot.CanvasAxisLabelRenderer,
tickRenderer: $.jqplot.CanvasAxisTickRenderer,
tickOptions: { labelPosition:'middle', angle: -30 }
},
yaxis: {
autoscale:true,
label: 'Total Time Spent',
labelRenderer: $.jqplot.CanvasAxisLabelRenderer,
tickRenderer: $.jqplot.CanvasAxisTickRenderer,
tickOptions: { labelPosition:'middle', angle: -30 }
}
}
});
//-------jqplot----!!! if i remove this block, will loop through customers------------
i++;
});//find customer
}//parse xml
解决方案:按照标记的建议进行了修改,并且有效。(现在,上面的代码工作!(
您正在将看起来像数组而不是实际数组的字符串传递给jqplot。
尝试:
var line_inside = []; // declare as array
$(this).find("page").each(function() {
var pageName = $(this).attr("name");
$(this).find("date_ts").each(function() {
var timeSpent_ = $(this).attr("timeSpent");//if mai multe timespent, sa faca totalul, else singuru; timespent
line_inside.push([pageName,timeSpent_]); //do not string cat, push onto array
});
});
alert(line_inside); // this is an array of arrays
var plot = $.jqplot('chart' + i, [line_inside],
因为您希望每个客户都有不同的绘图,所以您需要将plot作为内联函数的本地var:"var plot"而不仅仅是"plot"——"line"也是如此。当前,您正在分配一个全局作用域变量并每次覆盖它。
相关文章:
- 一段时间后使用Javascript加载网页ASP.net
- 关闭网页时没有显示 Js 的工作时间
- 我能得到网页加载的时间吗
- 获取Web服务器时间并将其显示在网页上的正确方法
- 更新网页上的计时器,并保持经过的时间--如何处理
- ASP.NET网页-使用脚本显示由预定义日期和时间指定的图像/文本
- 删除不需要的javascript和css是否包括减轻网页加载时间
- 在指定时间中添加 24 小时后在网页上显示时间 x
- 如何在自行携带的html网页上设置时间函数
- 如何获取网页加载时间
- 网页动画 API - 改变动画持续时间
- 使用jquery使网页在加载时需要很长时间
- 每周五在特定时间重定向网页
- Jquery/Javascript 允许在一周中的特定时间使用特定网页
- 在网页上将服务器的UTC日期时间转换为本地日期时间
- jQuery:抓取日期&来自网页的时间数据
- 网页中的图像会出现一小段时间,然后消失
- 在特定时间刷新网页,同时对用户隐藏网页
- 确定网页的一部分在浏览器中保持可见的时间
- 如何使用python在网页上提取动态时间计数器