1

I am in need of some assistance for my Radar Chart that I have created. I have created the Field Set, the Apex Class and the Visualforce Page for this. What I am having trouble with is, I need to place this Radar Chart on the Account Page Layout but I already have a Controller in my code so I cannot place a StandardController for it to be able to be on the Account. It Errors and says I can only have 1 Controller. Is there a way to do get this Radar Chart on the Account Layouts. My code is below;

APEX Class

public class RadarDemo{

    public RadarDemo() {

    }

    public List<Map<Object,Object>> data = new List<Map<Object,Object>>();
    public String acctId {get;set;}

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

    public List<Schema.FieldSetMember> getFields() {
        return SObjectType.Account.FieldSets.X7_Ps_Field_Set.getFields();
    }

    public List<Map<Object,Object>> getData() {
        String query = 'SELECT ';
        List<String> fieldNames = new List<String>();

        for(Schema.FieldSetMember f : getFields()){
            query += f.getFieldPath() + ', ';
            fieldNames.add(f.getFieldPath());
        }
        query += 'Id, Name FROM Account where Id=\'' + acctId + '\' LIMIT 1';

        SObject myFieldResults = Database.Query(query);
        Schema.DescribeSObjectResult R = myFieldResults.getSObjectType().getDescribe();
        Map<String, Schema.SObjectField> fieldMap = R.fields.getmap();

        //creates a map of labels and api names
        Map<String,String> labelNameMap = new Map<String,String>();
        for(String key : fieldMap.keySet()){
             labelNameMap.put(fieldMap.get(key).getDescribe().getName(), fieldMap.get(key).getDescribe().getlabel());
        }

        //creates a map of labels and values
        for(String f : fieldNames){
            String fieldLabel = labelNameMap.get(f);
            String fieldValue = String.valueOf(myFieldResults.get(f));

            Map<Object, Object> m = new Map<Object,Object>();
            m.put('field', fieldLabel);
            m.put('value', fieldValue);
            data.add(m);
        }

        return data;
    }
}

Visualforce page

<apex:page controller="RadarDemo">
    <style>
         #vfext4-ext-gen1026 {
        width:800px !important;
         }
    </style>  

        <apex:chart name="myChart" height="600" width="650" legend="false" data="{!data}">
             <apex:legend position="left" />
             <apex:axis type="Radial" position="radial"/>
             <apex:radarSeries title="7 Ps" xField="field" yField="value" tips="true" opacity="0.4"/>
        </apex:chart>
</apex:page>

Thanks in advance.

  • It is not a point to post demo code, but point is to post code, that give you an error. What do you mean by Account layouts? – kurunve Nov 23 '16 at 16:56
0

If you change your first line to

<apex:page standardController="Account" extensions="RadarDemo">

You will then be able to get your page into the Account Layout, if you look in the Visualforce area.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for?Browse other questions tagged or ask your own question.