Export to Csv not showing all the values but showing only 1 value in excel file

112 views
Skip to first unread message

nishh

unread,
Sep 24, 2012, 12:38:01 AM9/24/12
to google-visua...@googlegroups.com
i have created an export to csv file in google charts but the problem is it is showing me 1 value instead of all the value which are coming in arraylist.

<apex:page controller="WasteSplit" sidebar="false"> 
    <!-- Google API inclusion -->
    <apex:includeScript id="a" value="https://www.google.com/jsapi" />
    <apex:sectionHeader title="Google Charts" subtitle="Chart 2"/>
    
    <apex:form >
        <table align="center">
            <td><b>Date From:</b>
            <input id="t" name="datee" onfocus="DatePicker.pickDate(false,'t', false);"
                 size="12" tabindex="28" type="date" />
            </td><td></td>
            <td></td>
            <td></td>
            <td></td>
            <td><b>Date To:</b>
            <apex:outputText value="{0,date,dd/MM/yyyy}">
                <apex:param value="{!NOW()}" />
            </apex:outputText></td> 
            <td><input type="button" onclick="initCharts()" value="Go"></input></td>
            <td><input id="exportCSV" type="button" onclick="window.open('/apex/CSVWasteSplit?name=' + Name + '&type=' + Type);" value="Export to CSV" style="display: none;"></input></td>
        </table>
     </apex:form>
    <div id="chartBlock" style="width: 600px; height: 500px;"/>
    
    <script type="text/javascript">   
        // Load the Visualization API and the piechart package.
        google.load('visualization', '1', {'packages':['corechart']});
        // Set a callback to run when the Google Visualization API is loaded.
        google.setOnLoadCallback(initCharts);
     
      
        function initCharts() {
            var dateFrom= $('#t').val();
            document.getElementById('chartBlock').innerHTML = ''; 
            document.getElementById('exportCSV').style.display = 'none'; 
            Name = '';
            Type = '';     
            if(dateFrom != null && dateFrom != '')
            {
                WasteSplit.WasteSource(
                   dateFrom,function(result, event){
                     // load Column chart
                   if (event.status && event.result) 
                   {
                       var visualization = new google.visualization.PieChart(document.getElementById('chartBlock'));
                       // Prepare table model for chart with columns
                       var data = new google.visualization.DataTable();
                           data.addColumn('string', 'Waste Name');
                           data.addColumn('number', 'Waste Type');
                          
                           // add rows from the remoting results
                       for(var i=0; i<result.length;i++){
                           var finalBean= result[i];
                           data.addRow([finalBean.WasteName,finalBean.wastetype]);
                       }
//here m passing the the value of array list for exporting it to csv
                       if(finalBean.WasteName != null && finalBean.wastetype != null)
                       {
                         Name = finalBean.WasteName;
                         Type = finalBean.wastetype;
                         document.getElementById('exportCSV').style.display = 'block'; 
                       }
                          
                    } else {
                           alert(event.message);
                    }       
                         
                          visualization.draw(data,{title:'Waste Service Split at Source',legend : {position: 'bottom', textStyle: {color: 'blue', fontSize: 10}}, width:window.innerWidth,vAxis:{textStyle:{color:'red', fontSize: 15}},hAxis:{title: 'Record Count',textStyle:{fontSize: 10},showTextEvery:1,slantedText:true}} );
                }, {escape:true});
            }             
        }
    </script> 
</apex:page>



the values are 


waste name          waste Type

General                    35

Dry Mixed                  20

No waste                  1

cardboard                56

 

must be like this when exporting

 

but it is showing only 1 value

Waste Name              Waste Type

No Waste                         1



can anyone help me in that

asgallant

unread,
Sep 24, 2012, 2:26:26 AM9/24/12
to google-visua...@googlegroups.com
I don't know what your server-side code does to handle this on the back end, but I suspect that the problem is that you are only passing one name (whichever is the last in the result array) to the server-side CSV script.

nishh

unread,
Sep 24, 2012, 2:44:00 AM9/24/12
to google-visua...@googlegroups.com
yes u r absolutely right
this is my debug values

=====SplitList======(WasteSplitt:[WasteName=General, wastetype=80], WasteSplitt:
                     [WasteName=Dry Mixed Recycling, wastetype=45], 
                     WasteSplitt:[WasteName=Cardboard Stickers, wastetype=7], 
                     WasteSplitt:[WasteName=Sanitary, wastetype=1], 
                     WasteSplitt:[WasteName=Glass, wastetype=2], 
                     WasteSplitt:[WasteName=No Waste, wastetype=1])

  
 
and it is showing me last value of no waste=1

This is my page on which i am redirecting  
public with sharing class googleChartsCSV2Controller {

    public String strValues { get; set; }

    public String strHeaders { get; set; }
    
    public googleChartsCSV2Controller()
    {
        String wasName = ApexPages.currentPage().getParameters().get('name');
        String wasType = ApexPages.currentPage().getParameters().get('type');
        strHeaders = 'Waste Name, Waste Type';
        strValues = wasName + ',' + wasType;
    }
}

can u help me in this

Copyright © 2000-2012 salesforce.com, inc. All rights reserved. | Privacy Statement | Security Statement | Terms of Use | 508 Compliance

asgallant

unread,
Sep 24, 2012, 12:36:25 PM9/24/12
to google-visua...@googlegroups.com
From what I've read, APEX doesn't have any good way to handle arrays from the query string, so you'll have to stringify your data arrays and then parse the strings into arrays on the server side.  Here's the js to do the first part:
var names [];
var types [];

// add rows from the remoting results
for (var 0result.lengthi++{
    var finalBean result[i];
    data.addRow([finalBean.WasteNamefinalBean.wastetype]);

    //here m passing the the value of array list for exporting it to csv
    if (finalBean.WasteName != null && finalBean.wastetype != null{
        names.push(finalBean.WasteName);
        types.push(finalBean.wastetype);
    }
}

if (names.length 0{
    Name names.join(',');
    Type types.join(',');

    document.getElementById('exportCSV').style.display 'block';
} 

I'm not familiar with APEX, but a quick google search turned up the String.split method, so maybe what you need on the server-side is:

public googleChartsCSV2Controller()
{
    List<String> wasName = ApexPages.currentPage().getParameters().get('name').split(',');
    List<String> wasType = ApexPages.currentPage().getParameters().get('type').split(',');
    strHeaders = 'Waste Name, Waste Type';
    // parse arrays into CSV format

nishh

unread,
Sep 25, 2012, 12:43:29 AM9/25/12
to google-visua...@googlegroups.com
hey thanks a lot u have made my day...
now all the values are showing in excel
but they are coming like

Waste Name        Waste Type
(General,dry Mixed,No waste,cardboard)(80,23,1,34)

is there a way to show them 
Waste Name        Waste Type
General                   80
Dy Mixed                 23
No waste                  1
Cardboard                34

asgallant

unread,
Sep 25, 2012, 10:10:50 AM9/25/12
to google-visua...@googlegroups.com
You'll have to figure out how to parse the arrays in APEX.  As I said, I don't know the language, so I can't help you there.
Reply all
Reply to author
Forward
0 new messages