AHHH.......
I never would have caught that.  Thanks a lot.
I've been battling this for hours.


On Tue, May 20, 2014 at 2:30 PM, Andrew Gallant <[email protected]>wrote:

> Here is your problem:
>
>
> scannedItems = new Object();
> scannedItems.Title = $(this).attr("ows_Title");
> scannedItems.totalPages = 0;
> scannedItems.totalPassed = 0;
> scannedItems.totalFailed = 0;
> scannedItems.score = 0;               
>
> anArray[i] = scannedItems;
> lanArray[i] = scannedItems;
>
>
> You are creating an object scannedItems, and then passing that object to
> both anArray and lanArray.  Javascript passes objects by reference, so
> anArray[0] *is the same object as* lanArray[0]:
>
> anArray[0].totalPages = 5;
> console.log(anArray[0].totalPages) // 5
> console.log(lanArray[0].totalPages) // 5
> lanArray[0].totalPages = 10;
> console.log(anArray[0].totalPages) // 10
> console.log(lanArray[0].totalPages) // 10
>
> So when you update your totals in each AJAX call, you are actually adding
> them to *both* arrays.  The solution to this is to use separate objects:
>
> anArray.push({
>     Title: $(this).attr("ows_Title"),
>     totalPages: 0,
>     totalPassed: 0,
>     totalFailed: 0,
>     score: 0
> });
> lanArray.push({
>     Title: $(this).attr("ows_Title"),
>     totalPages: 0,
>     totalPassed: 0,
>     totalFailed: 0,
>     score: 0
> });
>
>
> On Tuesday, May 20, 2014 1:30:23 PM UTC-4, TheInnovator wrote:
>
>> Any help with this would be much appreciated.
>> I have a dashboard that is supposed to render a google table based on the
>> month and year but it does not work correctly.
>> The data from one table gets transferred to another table and when you
>> click "Submit" multiple times, it adds up the numbers in the table.
>>
>> http://isaac.issharepoint.com/Web%20Part%20Page/508Dashboard.aspx
>>
>> Here's my list:
>> http://isaac.issharepoint.com/Lists/508%20Dashboard%20Data/AllItems.aspx
>>
>> Here's my code:
>> <script type="text/javascript" src="http://isaac.issharepoint.com/Script/
>> jquery-1.8.2.min.js" language="javascript"></script>
>> <script type="text/javascript" src="http://isaac.issharepoint.com/Script/
>> jquery.SPServices-0.7.2.min.js" language="javascript"></script>
>> <script type="text/javascript" src="http://isaac.issharepoint.com/Script/
>> utilityFunctions.js" language="javascript"></script>
>> <script type="text/javascript" src="http://isaac.issharepoint.com/Script/
>> jquery.mtz.monthpicker.js" language="javascript"></script>
>> <link rel="stylesheet" href="http://isaac.issharepoint.com/Script/
>> jquery-ui-1.10.4.custom.css">
>> <script type="text/javascript" src="https://www.google.com/jsapi
>> "></script>
>> <style>
>> .Alternate
>> {
>> background-color:#BDBDBD
>> }
>> .Footer
>> {
>> font-weight:bold;
>> }
>>
>> #vizTbl tr:last-child {
>>     font-weight: bold;
>> }
>>
>> #vizTbl tr:last-child td {
>>     background-color: #a7d5b3;
>> }
>>
>> </style>
>> <script type="text/javascript">
>> google.load("visualization", "1", {packages:["corechart", "table"]});
>>
>> anArray = new Array();
>> lanArray = new Array();
>> $(function() {
>> $('#autoThisMonth').monthpicker();
>> $('#autoLastMonth').monthpicker();
>> $('#manThisMonth').monthpicker();
>> $('#manLastMonth').monthpicker();
>>  $('#autoLastMonth').change(function() {
>> autoLastMonthDate = $('#autoLastMonth').val();
>> });
>>
>> // AND HERE
>> $('#autoThisMonth').change(function() {
>> autoThisMonthDate = $('#autoThisMonth').val();
>> });
>> var i=0;
>> $().SPServices({
>>     operation: "GetListItems",
>>     async: false,
>>     listName: "508 File Types",
>> CAMLViewFields: "<ViewFields><FieldRef Name='Title'></FieldRef></
>> ViewFields>",
>> CAMLQuery: "<Query><OrderBy><FieldRef Name='Title' /></OrderBy></Query>",
>>     completefunc: function (xData, Status) {
>> //alert(xData.responseXML.xml);
>>       $(xData.responseXML).SPFilterNode("z:row").each(function() {
>> scannedItems = new Object();
>> scannedItems.Title = $(this).attr("ows_Title");
>> scannedItems.totalPages = 0;
>> scannedItems.totalPassed = 0;
>> scannedItems.totalFailed = 0;
>> scannedItems.score = 0;
>>
>> anArray[i] = scannedItems;
>> lanArray[i] = scannedItems;
>> i++;
>>       });
>>      }
>>   });
>> });
>>
>>
>> function getMonthsFunc()
>> {
>>
>> var spltDte = autoThisMonthDate.split("/");
>> var monthDte = spltDte[0];
>> var yearDte  = spltDte[1];
>>  /*--------------------------------------------------------------------This
>> Month Automatic---------------------------------------------------
>> ----------------------*/
>> var monthWord = convertMonthIndex(Number(monthDte));
>>  $().SPServices({
>> operation: "GetListItems",
>> async: false,
>> listName: "508 Dashboard Data",
>> CAMLViewFields: "<ViewFields><FieldRef Name='Title'></FieldRef><FieldRef
>> Name='Year'></FieldRef><FieldRef Name='FileType'></FieldRef><FieldRef
>> Name='TotalFailed'></FieldRef><FieldRef 
>> Name='TotalPassed'></FieldRef><FieldRef
>> Name='TotalScanned'></FieldRef><FieldRef Name='score'></FieldRef></
>> ViewFields>",
>> CAMLQuery: qry(monthWord, yearDte), //Function to call query
>> completefunc: function (xData, Status) {
>>   $(xData.responseXML).SPFilterNode("z:row").each(function() {
>> for (var x=0; x < anArray.length; x++)
>> {
>> var fileType = getDte($(this).attr("ows_FileType"));
>> if (fileType == anArray[x].Title)
>> {
>> anArray[x].totalPages += Number($(this).attr("ows_TotalScanned"));
>> anArray[x].totalPassed += Number($(this).attr("ows_TotalPassed"));
>> anArray[x].totalFailed += Number($(this).attr("ows_TotalFailed"));
>> anArray[x].score = Number($(this).attr("ows_
>> TotalPassed"))/Number($(this).attr("ows_TotalScanned"));
>> x++;
>> }
>> }
>>   });
>>  }
>>   });
>>  //This Month Automatic
>>     var thisAtutoMonthDataTbl = new google.visualization.DataTable();
>>     thisAtutoMonthDataTbl.addColumn('string', 'File Type');
>>     thisAtutoMonthDataTbl.addColumn('number', 'Total Pages');
>> thisAtutoMonthDataTbl.addColumn('number', 'Total Passed');
>> thisAtutoMonthDataTbl.addColumn('number', 'Total Failed');
>> thisAtutoMonthDataTbl.addColumn('number', 'Score');
>>   //Data for table chart
>>   $.each(anArray, function (index, value) {
>>         thisAtutoMonthDataTbl.addRow([anArray[index].Title,
>> Number(anArray[index].totalPages), Number(anArray[index].totalPassed),
>> Number(anArray[index].totalFailed), anArray[index].score*100]);
>>  });
>>
>>  var table = new google.visualization.Table(document.getElementById('
>> ThisAutoMonth'));
>> var tblOption = {
>> showRowNumber: true,
>> height:305,
>> width:200,
>> alternatingRowStyle: true,
>> cssClassNames: {
>>             tableRow: 'Alternate',
>> selectedTableRow: 'Footer'
>> }
>> };
>>  table.draw(thisAtutoMonthDataTbl, tblOption);
>> /*--------------------------------------------------------------------This
>> Month Automatic---------------------------------------------------
>> ----------------------*/
>>
>>
>> /*--------------------------------------------------------------------Last
>> Month Automatic---------------------------------------------------
>> ----------------------*/
>> var spltDte = autoLastMonthDate.split("/");
>> var monthDte = spltDte[0];
>> var yearDte  = spltDte[1];
>>  var monthWord = convertMonthIndex(Number(monthDte));
>>  $().SPServices({
>> operation: "GetListItems",
>> async: false,
>> listName: "508 Dashboard Data",
>> CAMLViewFields: "<ViewFields><FieldRef Name='Title'></FieldRef><FieldRef
>> Name='Year'></FieldRef><FieldRef Name='FileType'></FieldRef><FieldRef
>> Name='TotalFailed'></FieldRef><FieldRef 
>> Name='TotalPassed'></FieldRef><FieldRef
>> Name='TotalScanned'></FieldRef><FieldRef Name='score'></FieldRef></
>> ViewFields>",
>> CAMLQuery: qry(monthWord, yearDte), //Function to call query
>> completefunc: function (xData, Status) {
>>   $(xData.responseXML).SPFilterNode("z:row").each(function() {
>> for (var x=0; x < lanArray.length; x++)
>> {
>> var fileType = getDte($(this).attr("ows_FileType"));
>> if (fileType == lanArray[x].Title)
>> {
>> lanArray[x].totalPages += Number($(this).attr("ows_TotalScanned"));
>> lanArray[x].totalPassed += Number($(this).attr("ows_TotalPassed"));
>> lanArray[x].totalFailed += Number($(this).attr("ows_TotalFailed"));
>> lanArray[x].score = Number($(this).attr("ows_
>> TotalPassed"))/Number($(this).attr("ows_TotalScanned"));
>> x++;
>> }
>> }
>>   });
>>  }
>>   });
>>  //This Month Automatic
>>     var lastAtutoMonthDataTbl = new google.visualization.DataTable();
>>     lastAtutoMonthDataTbl.addColumn('string', 'File Type');
>>     lastAtutoMonthDataTbl.addColumn('number', 'Total Pages');
>> lastAtutoMonthDataTbl.addColumn('number', 'Total Passed');
>> lastAtutoMonthDataTbl.addColumn('number', 'Total Failed');
>> lastAtutoMonthDataTbl.addColumn('number', 'Score');
>>   //Data for table chart
>>   $.each(lanArray, function (index, value) {
>>         lastAtutoMonthDataTbl.addRow([lanArray[index].Title,
>> Number(lanArray[index].totalPages), Number(lanArray[index].totalPassed),
>> Number(lanArray[index].totalFailed), lanArray[index].score*100]);
>>  });
>>
>>  var tableLMA = new google.visualization.Table(document.getElementById('
>> LastAutoMonth'));
>> var tblOptionLMA = {
>> showRowNumber: true,
>> height:305,
>> width:200,
>> alternatingRowStyle: true,
>> cssClassNames: {
>>             tableRow: 'Alternate',
>> selectedTableRow: 'Footer'
>> <span class="Apple-tab-s
>> ...
>
>  --
> You received this message because you are subscribed to a topic in the
> Google Groups "Google Visualization API" group.
> To unsubscribe from this topic, visit
> https://groups.google.com/d/topic/google-visualization-api/aXrnZniQ7Es/unsubscribe
> .
> To unsubscribe from this group and all its topics, send an email to
> [email protected].
> To post to this group, send email to
> [email protected].
> Visit this group at
> http://groups.google.com/group/google-visualization-api.
> For more options, visit https://groups.google.com/d/optout.
>



-- 
-Isaac-

http://twitter.com/#!/feedy0urmind
You are today where your thoughts have brought you; you will be tomorrow
where your thoughts take you.
- James Allen

-- 
You received this message because you are subscribed to the Google Groups 
"Google Visualization API" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/google-visualization-api.
For more options, visit https://groups.google.com/d/optout.

Reply via email to