function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
jblon1973jblon1973 

Parsing and Plotting

Ok. So here is what I am trying to do. I have received two different fields that contain the information for plot points on a scatter graph. They are in Long text fields and seperated by 1 space:

 

ex: 

Channel Flow : 00.123456 00.123457 00.123458 etc...

Channel Volume: -00.987654 -00.987653 -00.987652 etc...

 

What I need to do is three fold:

 

1) I need to split these values

2) I need to convert the values into decimals 

3) I need to plot Channel Volume vs. Channel Flow on a graph

 

I am using google visualizations and at this point I feel like I am lost. The starting of my code is below:

public String getTimeVolume(List<Id> ids){
        GoogleViz gv = new GoogleViz();              
        gv.cols = new list<GoogleViz.col> { 
            new GoogleViz.Col('col2','Interval','number'),
            new GoogleViz.Col('col1','Channel Volume','number')
            };
        decimal interval = 0;
        for(Trial__c tfv : [Select Id, Channel_Volume__c from Trial__c])
        {
        	Integer v;
        	List<String> cv = tfv.Channel_Volume__c.split(' ');
        	for(v = 0; v < cv.count; v++)
{
            GoogleViz.row r = new GoogleViz.row();
            r.cells.add ( new GoogleViz.cell( interval));//interval
            r.cells.add ( new GoogleViz.cell( tfv.Channel_Volume__c[v]));//X-Axis
            gv.addRow( r ); 
            interval = interval + .01;
            }
        }

 I feel like I am on the rigth track, but am missing something. Currently the error that compiling is producing is:

Expresssion must be a list type: String

Best Answer chosen by Admin (Salesforce Developers) 
jblon1973jblon1973

So here was the final code that worked for this solution:

public with sharing class TestResultGraphConroller {

  
    public TestResultGraphConroller(ApexPages.StandardController stdController){
    }
    
    
    public String getTimeVolume(){
        return getTimeVolume(null);
    }
    
    public String getTimeVolume(List<Id> ids){
        GoogleViz gv = new GoogleViz();              
        gv.cols = new list<GoogleViz.col> { 
            new GoogleViz.Col('col2','Interval','number'),
            new GoogleViz.Col('col1','Channel Volume','number')
            };
        decimal interval = 0;
        for(Trial__c tv : [Select Id, Channel_Volume__c from Trial__c])
        {
        	Integer v;
        	List<String> channelvolumevalues = tv.Channel_Volume__c.split(' ');
        	for(String cv: channelvolumevalues)
        	{
            GoogleViz.row r = new GoogleViz.row();
            r.cells.add ( new GoogleViz.cell( interval));//interval
            r.cells.add ( new GoogleViz.cell( cv ));//X-Axis
            gv.addRow( r ); 
            interval = interval + .01;
            }
        }
        return gv.toJsonString();
    }
}

 

All Answers

sfdcfoxsfdcfox
r.cells.add ( new GoogleViz.cell( tfv.Channel_Volume__c[v]));//X-Axis

should be:

 

r.cells.add ( new GoogleViz.cell( cv[v] ));//X-Axis
jblon1973jblon1973

That solved one issue, now I am receiving the following:

 

Save Error: Method does not exist or incorrect signature: [List<String>].count()

 

I am trying to count the amount of values to iterate through on teh for loop. Is there a better way to do this?

 

JP

jblon1973jblon1973

So now I have changed the code to below and am getting the error:

 

constructor not defined: [GoogleViz.cell].<Constructor>(List<String>)

 

public with sharing class TestResultGraphConroller {

  
    public TestResultGraphConroller(ApexPages.StandardController stdController){
    }
    
    
    public String getTimeVolume(){
        return getTimeVolume(null);
    }
    
    public String getTimeVolume(List<Id> ids){
        GoogleViz gv = new GoogleViz();              
        gv.cols = new list<GoogleViz.col> { 
            new GoogleViz.Col('col2','Interval','number'),
            new GoogleViz.Col('col1','Channel Volume','number')
            };
        decimal interval = 0;
        for(Trial__c tfv : [Select Id, Channel_Volume__c from Trial__c])
        {
        	Integer v;
        	for(List<String> cv : tfv.Channel_Volume__c.split(' '))
        	//for(v = 0; v < cv.count(); v++)       
            {
            GoogleViz.row r = new GoogleViz.row();
            r.cells.add ( new GoogleViz.cell( interval));//interval
            r.cells.add ( new GoogleViz.cell( cv ));//X-Axis
            gv.addRow( r ); 
            interval = interval + .01;
            }
        }
        return gv.toJsonString();
    }

 any suggestions?

 

 

jblon1973jblon1973

So here was the final code that worked for this solution:

public with sharing class TestResultGraphConroller {

  
    public TestResultGraphConroller(ApexPages.StandardController stdController){
    }
    
    
    public String getTimeVolume(){
        return getTimeVolume(null);
    }
    
    public String getTimeVolume(List<Id> ids){
        GoogleViz gv = new GoogleViz();              
        gv.cols = new list<GoogleViz.col> { 
            new GoogleViz.Col('col2','Interval','number'),
            new GoogleViz.Col('col1','Channel Volume','number')
            };
        decimal interval = 0;
        for(Trial__c tv : [Select Id, Channel_Volume__c from Trial__c])
        {
        	Integer v;
        	List<String> channelvolumevalues = tv.Channel_Volume__c.split(' ');
        	for(String cv: channelvolumevalues)
        	{
            GoogleViz.row r = new GoogleViz.row();
            r.cells.add ( new GoogleViz.cell( interval));//interval
            r.cells.add ( new GoogleViz.cell( cv ));//X-Axis
            gv.addRow( r ); 
            interval = interval + .01;
            }
        }
        return gv.toJsonString();
    }
}

 

This was selected as the best answer