Note that there are some explanatory texts on larger screens.

plurals
  1. POwhat's wrong with this automatic creation of charts for time spent on webpages?
    primarykey
    data
    text
    <p><strong>!SOLVED!</strong></p> <p>I want to <strong>automatically create charts</strong> with users and their <strong>time spent on pages</strong> of a website.</p> <p>I have a file - "log.xml" where I keep information with users (customers), visited pages, dates and their time spent; and after I "get" this Xml file with Ajax, I want to parse it and create with values "extracted" charts with JqPlot.</p> <p><strong>My problem</strong> is that I can't loop through more than just one customer and it don't build chart for the single customer.</p> <p>If I <strong>remove the code block</strong> with initialization of variable <code>plot</code> I <strong>can loop</strong> through all my customers from Xml.</p> <p>Please, if someone can tell me what is wrong, and how to create charts for all customers...</p> <p>Here is the code of the file "<strong>log.xml</strong>":</p> <pre><code>&lt;?xml version="1.0"?&gt; &lt;log&gt; &lt;customer id="14" name="Florin Virdol"&gt; &lt;page name="/mobilestore/index.php"&gt; &lt;date_ts on="2011-12-02" timeSpent="205"/&gt; &lt;/page&gt; &lt;page name="/mobilestore/products_all.php"&gt; &lt;date_ts on="2011-12-02" timeSpent="15"/&gt; &lt;/page&gt; &lt;/customer&gt; &lt;customer id="0" name="guest"&gt; &lt;page name="/mobilestore/services.php"&gt; &lt;date_ts on="2011-12-02" timeSpent="50"/&gt; &lt;/page&gt; &lt;/customer&gt; &lt;/log&gt; </code></pre> <p>Here is the javascript code of the "operations":</p> <pre><code>$(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() { $('&lt;div class = "jqplot graph" id = "chart' + i + '"&gt;&lt;/div&gt;').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 </code></pre> <p><strong>SOLUTION</strong>: made modifications that <strong>Mark</strong> suggested, and it works. (now, above code works!)</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload