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
NEW.ax1607NEW.ax1607 

VF Charting

I have created VF page and apex Controller to construct a Gauge chart but when I try open the chart I've this error message:

Attempt to de-reference a null object

 

Does anyone can help me please? I´m new on this and I don't know how can I solve this problem. Thnak you.

 

when I make debug the error are indicated in this code:

AggregateResult ClosedWonOpptys =[select SUM(Amount) totalRevenue, CALENDAR_MONTH(CloseDate) theMonth, COUNT(Name) numOpps
from Opportunity
where AccountId =: acctId
and StageName = 'Closed Won'
and CALENDAR_MONTH(CloseDate) =: thisMonth
GROUP BY CALENDAR_MONTH(CloseDate) LIMIT 1];

 

my Class apex:

public class GaugeChartController {
public Account a {get; set;}
public String acctId {get;set;}
public Integer totalRevenue {get; set;}
//public Integer thisMonth = date.Today().month();
public boolean render {get; set;}

public GaugeChartController(ApexPages.StandardController controller){
acctId = controller.getRecord().Id;

//render=true;

/* try{
a = [SELECT Id, Name, Site, owner.name, phone,billingstreet,billingstate,billingcountry,billingcity FROM Account
WHERE Id = :ApexPages.currentPage().getParameters().get('id')];
}
catch(Exception ex1){
System.Debug('We did not find the Account' + ex1);
}

AggregateResult renderCheck = [select Count(id) numOpps, SUM(Amount) totalRev from Opportunity where Accountid = :a.id
AND CALENDAR_YEAR(CloseDate) = :thisMonth];

//checking if there are any related Opps, and aggregating their revenue
System.Debug('Number of Opps returned in query is ' + Integer.valueOf(renderCheck.get('numOpps')));
if(Integer.valueOf(renderCheck.get('numOpps')) > 0){
render=true;
totalRevenue = Integer.valueOf(renderCheck.get('totalRev'));
}*/


}

public List<gaugeData> getData() {
    Integer TotalOpptys = 0;
    Integer TotalAmount = 0;
    Integer thisMonth = date.Today().month();

 

   AggregateResult ClosedWonOpptys =[select SUM(Amount) totalRevenue, CALENDAR_MONTH(CloseDate)  theMonth, COUNT(Name) numOpps
                           from Opportunity
                           where AccountId =: acctId
                           and StageName = 'Closed Won'
                           and CALENDAR_MONTH(CloseDate) =: thisMonth
                           GROUP BY CALENDAR_MONTH(CloseDate) LIMIT 1];

   List<gaugeData> data = new List<gaugeData>();
   system.debug('debug2' + data.add(new gaugeData(Integer.valueOf(ClosedWonOpptys.get('numOpps')) + ' Deals', Integer.valueOf(ClosedWonOpptys.get('totalRevenue')))));


return data;


}

public class gaugeData {
public String name { get; set; }
public Integer size { get; set; }

 

public gaugeData(String name, Integer data) {
this.name = name;
this.size = data;
}
}
}

 

VF Page:

<apex:page standardController="Account" extensions="GaugeChartController">
<apex:chart name="MyChart" height="300" width="450" animate="true" data="{!data}">
<apex:axis type="Gauge" position="gauge" title="Closed Won Opportunities" minimum="0" maximum="30000" steps="10"/>
<apex:gaugeSeries dataField="size" donut="50" colorSet="#78c953,#ddd"/>
</apex:chart>

<script>
MyChart.on('beforeconfig', function(config) {
config.axes[0].margin=-10;
});
</script>

</apex:page>