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
Andrew AldisAndrew Aldis 

Add chart to VF page

I am trying to add a chart to a VF page with a standard controller.  The only examples of VF page charts work with controllers so when I try to add my chart as a extension I get he following error.  'Unknown construction 'BurnReportPieChartController.BurnReportPieChartController(ApexPages.StandardController controller)'  how can I add a chart to my page?  My controller and page are below.

COntroller 
public class BurnReportPieChartController {
    
 public List<PieWedgeData> getPieData() 
    {  
        List<PieWedgeData> data = new List<PieWedgeData>();
        List<SFDC_Project__c> install = new List<SFDC_Project__c>();  
        
        String sql = 'SELECT id, Logged_Billable_Time_All_Roles__c, Remaining_All_Budgeted_Hours__c FROM SFDC_Project__c';
        install = Database.Query(sql);
        for(SFDC_Project__c temp:install)
        {           
            data.add(new PieWedgeData('Logged Billable Hours',temp.Logged_Billable_Time_All_Roles__c));
            data.add(new PieWedgeData('Remaining Billable Hours',temp.Logged_Billable_Time_All_Roles__c));
        }
        return data;  
    }  
    
    // Wrapper class  
    public class PieWedgeData 
    {  
        public String name { get; set; }  
        public Decimal data { get; set; }  
        
        public PieWedgeData(String name, Decimal data) 
        {  
            this.name = name;  
            this.data = data;  
        }  
    }  
}

VF page
<apex:page standardController="SFDC_Project__c"  extensions="BurnReportPieChartController" DOCType="HTML-5.0" RenderAS="PDF">
    <apex:sectionHeader title="Installation" subtitle="{!SFDC_Project__c.Name}"/>
    <apex:pageBlock  >

        <apex:pageBlockSection title="General Project Information" columns="1" >
            <apex:outputField title="Account" value="{!SFDC_Project__c.Account__c}"/>
            <apex:outputField title="Installation Number" value="{!SFDC_Project__c.Name}" />
            <apex:outputField title="FWi Project Manager" value="{!SFDC_Project__c.SFDC_Project_Manager__c}" />
        </apex:pageBlockSection>
        <br/><br/>
        <Table Class="T">
            <tr Class="R1">
                <td Class="C1" style='width:350px; padding-right:40px'></td>
                <td Class="C2" >Budgeted</td>
                <td Class="C2">Logged</td>
                <td Class="C2">Remaining</td>
            </tr>
            <tr Class="R">
                <td Class="C1">Billable Time-Total</td>
                <td Class="C2" style='width:150px; padding-right:15px'><apex:outputField value="{!SFDC_Project__c.Budgeted_Billable_Hours__c}"/></td>
                <td Class="C2" style='width:150px; padding-right:15px'><apex:outputField Value="{!SFDC_Project__c.Logged_Billable_Time_All_Roles__c}"/></td>
                <td Class="C2" style='width:150px; padding-right:15px'><apex:outputField value="{!SFDC_Project__c.Remaining_All_Budgeted_Hours__c}"/></td>
            </tr>
            <tr Class="R">
                <td Class="C1">Billable Time-ASD</td>
                <td Class="C2"><apex:outputField value="{!SFDC_Project__c.Budgeted_Billable_Time_ASD__c}"/></td>
                <td Class="C2"><apex:outputField value="{!SFDC_Project__c.Logged_Billable_Time_ASD__c}"/></td>
                <td Class="C2"><apex:outputField value="{!SFDC_Project__c.Remaining_Billable_Hours_ASD__c}"/></td>
            </tr>
            <tr Class="R">
                <td Class="C1">Billable Time-Creative</td>
                <td Class="C2"><apex:outputField value="{!SFDC_Project__c.Budgeted_Billable_Time_Creative__c}"/></td>
                <td Class="C2"><apex:outputField value="{!SFDC_Project__c.Logged_Billable_Time_Creative__c}"/></td>
                <td Class="C2"><apex:outputField value="{!SFDC_Project__c.Remaining_Billable_Time_Creative__c}"/></td>
            </tr>
            <tr Class="R">
                <td Class="C1">Billable Time-Custom Development</td>
                <td Class="C2"><apex:outputField value="{!SFDC_Project__c.Budgeted_Billable_Time_Custom_Dev__c}"/></td>
                <td Class="C2"><apex:outputField value="{!SFDC_Project__c.Logged_Billable_Time_Custom_Dev__c}"/></td>
                <td Class="C2"><apex:outputField value="{!SFDC_Project__c.Remaining_Billable_Time_Custom_Dev__c}"/></td>
            </tr>
            <tr Class="R">
                <td Class="C1">Billable Time-Project Management</td>
                <td Class="C2"><apex:outputField value="{!SFDC_Project__c.Budgeted_Billable_Time_Project_Mgmt__c}"/></td>
                <td Class="C2"><apex:outputField value="{!SFDC_Project__c.Logged_Billable_Time_PM__c}"/></td>
                <td Class="C2"><apex:outputField value="{!SFDC_Project__c.Remaining_Billable_Time_PM__c}"/></td>
            </tr>
            <tr Class="R">
                <td Class="C1">Billable Time-Quality Assurance</td>
                <td Class="C2"><apex:outputField value="{!SFDC_Project__c.Budgeted_Billable_Hours_Time_QA__c}"/></td>
                <td Class="C2"><apex:outputField value="{!SFDC_Project__c.Logged_Billable_Time_QA__c}"/></td>
                <td Class="C2"><apex:outputField value="{!SFDC_Project__c.Remaining_Billable_Time_QA__c}"/></td>
            </tr>
            <tr Class="R">
                <td Class="C1">Billable Time-Sign Architecture 1</td>
                <td Class="C2"><apex:outputField value="{!SFDC_Project__c.Budgeted_Billable_Time_Signage_Arch_1__c}"/></td>
                <td Class="C2"><apex:outputField value="{!SFDC_Project__c.Logged_Billable_Time_Sign_Arch_1__c}"/></td>
                <td Class="C2"><apex:outputField value="{!SFDC_Project__c.Remaining_Billable_Time_Sign_Arch_1__c}"/></td>
            </tr>
            <tr Class="R">
                <td Class="C1">Billable Time-Sign Architecture 2</td>
                <td Class="C2"><apex:outputField value="{!SFDC_Project__c.Budgeted_Billable_Time_Signage_Arch_2__c}"/></td>
                <td Class="C2"><apex:outputField value="{!SFDC_Project__c.Logged_Billable_Time_Sign_Arch_2__c}"/></td>
                <td Class="C2"><apex:outputField value="{!SFDC_Project__c.Remaining_Billable_Time_Sign_Arch_2__c}"/></td>
            </tr>
            <tr Class="R">
                <td Class="C1">Billable Time-System Engineer</td>
                <td Class="C2"><apex:outputField value="{!SFDC_Project__c.Budgeted_Billable_Time_Systems_Engineer__c}"/></td>
                <td Class="C2"><apex:outputField value="{!SFDC_Project__c.Logged_Billable_Time_Systems_Engineer__c}"/></td>
                <td Class="C2"><apex:outputField value="{!SFDC_Project__c.Remaining_Billable_Time_Systems_Engineer__c}"/></td>
            </tr>
            <tr Class="R">
                <td Class="C1">Billable Time-Training</td>
                <td Class="C2"><apex:outputField value="{!SFDC_Project__c.Budgeted_Billable_Time_Training__c}"/></td>
                <td Class="C2"><apex:outputField value="{!SFDC_Project__c.Logged_Billable_Time_Training__c}"/></td>
                <td Class="C2"><apex:outputField value="{!SFDC_Project__c.Remaining_Billable_Time_Training__c}"/></td>
            </tr>
        </Table>
           
    <apex:pageblock title="Logged vs. Remaining Billable Hours" >
        <apex:chart height="250" width="350" data="{!pieData}"> 
            <apex:pieSeries tips="true" dataField="data" labelField="name"/> 
            <apex:legend position="bottom"/>
        </apex:chart>
    </apex:pageblock>
    </apex:pageBlock>
</apex:page>
   
 
Veenesh VikramVeenesh Vikram
Hi,

The issue here is that you are using your Apex Class as an Extension to a Standard controller. However you dont have a constructor defined in your class which will take a standard controller for initialization (Extension Constructor). Adding such a constructor to your class will resolve the issue.

Your class should look something like this:
public class BurnReportPieChartController {

private SFDC_Project__c project ;

 //This is the extension constructor
 public BurnReportPieChartController (ApexPages.StandardController stdController) { 
     this.project = (SFDC_Project__c)stdController.getRecord(); 
    } 
    
 public List<PieWedgeData> getPieData() 
    {  
        List<PieWedgeData> data = new List<PieWedgeData>();
        List<SFDC_Project__c> install = new List<SFDC_Project__c>();  
        
        String sql = 'SELECT id, Logged_Billable_Time_All_Roles__c, Remaining_All_Budgeted_Hours__c FROM SFDC_Project__c';
        install = Database.Query(sql);
        for(SFDC_Project__c temp:install)
        {           
            data.add(new PieWedgeData('Logged Billable Hours',temp.Logged_Billable_Time_All_Roles__c));
            data.add(new PieWedgeData('Remaining Billable Hours',temp.Logged_Billable_Time_All_Roles__c));
        }
        return data;  
    }  
    
    // Wrapper class  
    public class PieWedgeData 
    {  
        public String name { get; set; }  
        public Decimal data { get; set; }  
        
        public PieWedgeData(String name, Decimal data) 
        {  
            this.name = name;  
            this.data = data;  
        }  
    }  
}
Kindly mark as solved if this resolves your issue.

Regards
Veenesh