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
SushupsiSushupsi 

Google Visualizations Line Chart

Hi All,

 

I have been using the google visualizations to show some data realted to account. I have an object which looks like this:

 Field Name    Field Type

Account          Look up to Account

Type    Actual, Budget or Forecast

UOM/Currency           Identify UOM or Currency

Year    Number

Jan       Number

Feb      Number

March  Number

April    Number

May     Number

June     Number

July      Number

Aug     Number

Sept     Number

Oct      Number

Nov     Number

Dec      Number

 Records exist for various years with data for months and a Type. Based on the Type i need to pick the values of the months and show a graph like this:

 

Values on Y axis and Months on X-axis.

 

 

I am struggling with the VisualForce lineChart Component from the Code Share Project. i am not able to understand how can i associate multiple chart data into a JaSON object. Please advice.

 

 @BobBuzzard - please can you help me with the same.

 

 

Best Answer chosen by Admin (Salesforce Developers) 
SushupsiSushupsi

Hi Bob,

 

I finally was able to crack the nut :) The way i did it is that "visualization Project" over the developer forums and figured out passing the values to the Line Graph.

 

Please let me know if my code is optimal :)

    	GoogleViz gv = new GoogleViz();
    	gv.cols = new list<GoogleViz.col> {
    		new GoogleViz.Col('col1','Month','String'),
    		new GoogleViz.Col('col2','Sales','Number'),
    		new GoogleViz.Col('col3','Budget','Number')
    		//new GoogleViz.Col('col4','Forecast','Number'),
    		//new GoogleViz.Col('col5','PrevSales','Number')
    	};
    	Map<String,Decimal> sales = new Map<String,Decimal>();
    	Map<String,Decimal> budget = new Map<String,Decimal>();
    	for ( integer index = 0 ;  index < accSummaryMonth.size() ; index++ ){
    		if ( accSummaryMonth[index].Type__c == 'Actual' ) {
    			sales.put('M-1',accSummaryMonth[index].Jan__c);
    			sales.put('M-2',accSummaryMonth[index].Feb__c);
    			sales.put('M-3',accSummaryMonth[index].March__c);
    			sales.put('M-4',accSummaryMonth[index].April__c);
    			sales.put('M-5',accSummaryMonth[index].May__c);
    			sales.put('M-6',accSummaryMonth[index].June__c);
    			sales.put('M-7',accSummaryMonth[index].July__c);
    			sales.put('M-8',accSummaryMonth[index].Aug__c);
    			sales.put('M-9',accSummaryMonth[index].Sept__c);
    			sales.put('M-10',accSummaryMonth[index].Oct__c);
    			sales.put('M-11',accSummaryMonth[index].Nov__c);
    			sales.put('M-12',accSummaryMonth[index].Dec__c);
    		}
    	}


Adding data to the Rows:

    	for ( integer month = 1; month <= 12;month++ ) {
    		GoogleViz.row r = new GoogleViz.row();
    		if ( month == 1 )
    		r.cells.add ( new GoogleViz.cell('Jan') );
    		else if (month == 2)
    		r.cells.add ( new GoogleViz.cell('Feb') );
    		else if (month == 3)
    		r.cells.add ( new GoogleViz.cell('March') );
    		else if (month == 4)
    		r.cells.add ( new GoogleViz.cell('April') );
    		else if (month == 5)
    		r.cells.add ( new GoogleViz.cell('May') );
    		else if (month == 6)
    		r.cells.add ( new GoogleViz.cell('June') );
    		else if (month == 7)
    		r.cells.add ( new GoogleViz.cell('July') );
    		else if (month == 8)
    		r.cells.add ( new GoogleViz.cell('Aug') );
    		else if (month == 9)
    		r.cells.add ( new GoogleViz.cell('Sep') );
    		else if (month == 10)
    		r.cells.add ( new GoogleViz.cell('Oct') );
    		else if (month == 11)
    		r.cells.add ( new GoogleViz.cell('Nov') );
    		else if (month == 12)
    		r.cells.add ( new GoogleViz.cell('Dec') );

    		r.cells.add ( new GoogleViz.cell(sales.get('M'+'-'+(month))));
    		r.cells.add ( new GoogleViz.cell(budget.get('M'+'-'+(month))));
    		gv.addRow( r );
    	}

 

 

Warm Regards,

M.Sushumna

All Answers

bob_buzzardbob_buzzard

I'm afraid that's an area I haven't used.  I have created a chart with two line plots and an axis on the left and right, but I did that by passing information the URL and retrieving an image from the google viz server.

SushupsiSushupsi

Hi Bob,

 

I finally was able to crack the nut :) The way i did it is that "visualization Project" over the developer forums and figured out passing the values to the Line Graph.

 

Please let me know if my code is optimal :)

    	GoogleViz gv = new GoogleViz();
    	gv.cols = new list<GoogleViz.col> {
    		new GoogleViz.Col('col1','Month','String'),
    		new GoogleViz.Col('col2','Sales','Number'),
    		new GoogleViz.Col('col3','Budget','Number')
    		//new GoogleViz.Col('col4','Forecast','Number'),
    		//new GoogleViz.Col('col5','PrevSales','Number')
    	};
    	Map<String,Decimal> sales = new Map<String,Decimal>();
    	Map<String,Decimal> budget = new Map<String,Decimal>();
    	for ( integer index = 0 ;  index < accSummaryMonth.size() ; index++ ){
    		if ( accSummaryMonth[index].Type__c == 'Actual' ) {
    			sales.put('M-1',accSummaryMonth[index].Jan__c);
    			sales.put('M-2',accSummaryMonth[index].Feb__c);
    			sales.put('M-3',accSummaryMonth[index].March__c);
    			sales.put('M-4',accSummaryMonth[index].April__c);
    			sales.put('M-5',accSummaryMonth[index].May__c);
    			sales.put('M-6',accSummaryMonth[index].June__c);
    			sales.put('M-7',accSummaryMonth[index].July__c);
    			sales.put('M-8',accSummaryMonth[index].Aug__c);
    			sales.put('M-9',accSummaryMonth[index].Sept__c);
    			sales.put('M-10',accSummaryMonth[index].Oct__c);
    			sales.put('M-11',accSummaryMonth[index].Nov__c);
    			sales.put('M-12',accSummaryMonth[index].Dec__c);
    		}
    	}


Adding data to the Rows:

    	for ( integer month = 1; month <= 12;month++ ) {
    		GoogleViz.row r = new GoogleViz.row();
    		if ( month == 1 )
    		r.cells.add ( new GoogleViz.cell('Jan') );
    		else if (month == 2)
    		r.cells.add ( new GoogleViz.cell('Feb') );
    		else if (month == 3)
    		r.cells.add ( new GoogleViz.cell('March') );
    		else if (month == 4)
    		r.cells.add ( new GoogleViz.cell('April') );
    		else if (month == 5)
    		r.cells.add ( new GoogleViz.cell('May') );
    		else if (month == 6)
    		r.cells.add ( new GoogleViz.cell('June') );
    		else if (month == 7)
    		r.cells.add ( new GoogleViz.cell('July') );
    		else if (month == 8)
    		r.cells.add ( new GoogleViz.cell('Aug') );
    		else if (month == 9)
    		r.cells.add ( new GoogleViz.cell('Sep') );
    		else if (month == 10)
    		r.cells.add ( new GoogleViz.cell('Oct') );
    		else if (month == 11)
    		r.cells.add ( new GoogleViz.cell('Nov') );
    		else if (month == 12)
    		r.cells.add ( new GoogleViz.cell('Dec') );

    		r.cells.add ( new GoogleViz.cell(sales.get('M'+'-'+(month))));
    		r.cells.add ( new GoogleViz.cell(budget.get('M'+'-'+(month))));
    		gv.addRow( r );
    	}

 

 

Warm Regards,

M.Sushumna

This was selected as the best answer
krishna1krishna1

Hi Sushupsi,

 

Please provide me code of line chart, I have the same requirement.

 

Thanks

Krishna