0

I have a problem, i want to display a two charts when show button is clicked and hide them when the hide button is clicked. but it works only the first time i click on the show button (the hide button works properly), the second time no chart is displayed but the chart area is created, here is some pictures describing by problem:

enter image description here

when i click on the show button (the first time) the two charts are dispalyed correctly enter image description here

Now, here is the problem when i try to hide and show then another time i get this

enter image description here

Apex code:

Public class PID_Collaborateur {
    public string postid2 {get;set;}
    public string maxim {get;set;}
    public string BPid {get;set;}
    public String ItemNumber {get;set;}
    public boolean flagItem {get;set;}
    public List < Dataz > data2 {get;set;}
    public List < WrapperClass > MapPostePositionnement {get;set;}
    String collaborateurID = UserInfo.getUserId();
    public List < poste__c > listeDesCollaborateurs {get;set;}
    public List < Map < Object, Object >> data1 {get;set;}
    public list < Bilan_de_positionnement__c > bilan1 {get;set;}
    public PID_COllaborateur() {
        flagItem = false;
        ItemNumber = '1';
        if (collaborateurID != null && collaborateurID != '') {
            listeDesCollaborateurs = [select id, name, Date_dernier_bilan__c, collaborateur__r.name from poste__c where collaborateur__r.statut__c =: 'Actif'
                and collaborateur__r.manager__c =: collaborateurID
            ];
            if (listeDesCollaborateurs.size() > 0) {
                MapPostePositionnement = new List < WrapperClass > ();
                set < ID > collID = new set < ID > ();
                set < Date > CollDates = new set < Date > ();
                for (poste__c po: listeDesCollaborateurs) {
                    collID.add(po.id);
                    CollDates.add(po.Date_dernier_bilan__c);
                }
                bilan1 = [select id, valider__c, poste__c, Statut__c, Poste__r.Date_dernier_bilan__c, date_bilan__c, moyenne_du_bilan__c from Bilan_de_positionnement__c where poste__c in: collID and date_bilan__c in: CollDates order by date_bilan__c asc /*limit 1 */ ];
                system.debug('La taille des bilan = ' + bilan1.size());
                for (poste__c po2: listeDesCollaborateurs) {
                    for (Bilan_de_positionnement__c BP: bilan1) {
                        if (BP.poste__c == po2.id) {
                            system.debug('Le id de poste est = ' + po2.id + ' et le id de bilan est = ' + BP.id);
                            MapPostePositionnement.add(new WrapperClass(po2, BP));
                        }
                    }
                }
            }
        } else {

            ApexPages.Message myMsg = new ApexPages.Message(ApexPages.Severity.ERROR, 'Error: Aucun Id trouvé !!');
            ApexPages.addMessage(myMsg);
        }
    }

    public PageReference RadarData() {
        if (flagItem == false) {
            Data1 = new List < Map < Object, Object >> ();
            Competence__c[] comps;
            maxim = '4';
            comps = [select id, Poste__c, Poste__r.name, Name, Objectif__c, Niveau__c, Niveau_Prevue__c, Niveau_bilan__c from Competence__c where poste__c =: postid2 order by cod_order__c];
            //creates a map of labels and values
            for (Competence__c c: comps) {
                if (c.Niveau_bilan__c == null) {
                    c.Niveau_bilan__c = 0;
                }
                if (c.Poste__r.name == 'PM') {
                    maxim = '5';
                }
                String fieldLabel = c.Name;
                String fieldValue = String.valueOf(c.Niveau__c);
                String fieldPrevue = String.valueOf(c.Niveau_Prevue__c);
                String objValue = String.valueOf(c.Objectif__c);
                String bilanValue = String.valueOf(c.Niveau_bilan__c);
                Map < Object, Object > m = new Map < Object, Object > ();
                m.put('field', fieldLabel);
                m.put('value', fieldValue);
                m.put('prevue', fieldPrevue);
                m.put('objectif', objValue);
                m.put('Bilan', bilanValue);
                m.put('idd', c.Id);
                data1.add(m);
                Data2 = new List < Dataz > ();
                list < Bilan_de_positionnement__c > bilan = [select id, valider__c, Poste__c, date_bilan__c, moyenne_du_bilan__c from Bilan_de_positionnement__c where poste__c =: postid2 order by date_bilan__c asc];
                for (Bilan_de_positionnement__c b: bilan) {
                    String fieldLabel2 = String.valueOf(b.date_bilan__c);
                    decimal fieldValue2 = b.moyenne_du_bilan__c;
                    data2.add(new Dataz(fieldLabel2, fieldValue2));
                }
            }
            system.debug('le itemflag = ' + flagItem + ' et le set number = ' + ItemNumber);
            flagItem = true;
            ItemNumber = '2';
        } else {
            flagItem = false;
            ItemNumber = '1';
            system.debug('le itemflag = ' + flagItem + ' et le set number = ' + ItemNumber);
        }
        return null;
    }
    public class Dataz {
        public String name {get;set;}
        public decimal data1 {get;set;}
        public Dataz(String name, decimal data1) {
            this.name = name;
            this.data1 = data1;
        }
    }
    public pagereference ValiderBP() {
        if (BPid != null) {
            system.debug('le id de poste = ' + postid2);
            List < Bilan_de_positionnement__c > bilan2 = [select id, valider__c, poste__c, Statut__c, date_bilan__c, moyenne_du_bilan__c from Bilan_de_positionnement__c where id =: BPid limit 1];
            system.debug('La taille est = ' + bilan2.size() + ' le id de bilan est = ' + bilan2[0].id);
            if (bilan2.size() > 0) {
                if (bilan2[0].Statut__c != 'Validé') {
                    bilan2[0].Statut__c = 'Validé';
                }
                update bilan2;
            }
        }
        return null;
    }

    public class WrapperClass {
        public poste__c poste {get;set;}
        public Bilan_de_positionnement__c BP {get;set;}
        public WrapperClass(poste__c poste, Bilan_de_positionnement__c BP) {
            this.poste = poste;
            this.BP = BP;
        }
    }
}

visualforce code:

<apex:page controller="PID_Collaborateur">
    <apex:form>
        <apex:pageMessages></apex:pageMessages>
        <apex:pageBlock id="leblock2">
            <apex:pageBlockSection columns="{!itemNumber}">
                <apex:PageBlockSectionItem>
                    <apex:outputpanel>
                        <h3 class="panel-title">Liste Collaborateurs TOTAL :</h3>
                        <apex:pageBlockTable value="{!MapPostePositionnement}" var="item">
                            <apex:column headerValue="Poste de collaborateur">
                                <apex:outputtext value="{!item.poste.name}" />
                            </apex:column>
                            <apex:column headerValue="itemflag">
                                <apex:outputtext value="{!flagItem}" />
                            </apex:column>
                            <apex:column headerValue="sectin">
                                <apex:outputtext value="{!itemNumber}" />
                            </apex:column>
                            <apex:column headerValue="Valider le bilan de positionnnement">
                                <apex:commandButton value="Valider Le BP" action="{!ValiderBP}" disabled="{!item.BP.Statut__c =='Validé'}">
                                    <apex:param name="BPid" value="{!item.BP.id}" assignTo="{!BPid}" />
                                </apex:commandButton>
                            </apex:column>
                            <apex:column headerValue="Statut de bilan de positionnnement">
                                <apex:outputField value="{!item.BP.Statut__c}" />
                                <apex:outputField value="{!item.BP.id}" />
                            </apex:column>
                            <apex:column headerValue="Visualiser Le radar de positionnement">
                                <apex:commandButton value="Voir Graph + BP" action="{!RadarData}" rerender="leblock2" rendered="{!Not(flagItem)}">
                                    <apex:param name="Postid1" value="{!item.poste.id}" assignTo="{!postid2}" />
                                </apex:commandButton>
                                <apex:commandButton value="Fermer Graph + BP" action="{!RadarData}" rerender="leblock2" rendered="{!flagItem}">
                                    <apex:param name="Postid1" value="{!item.poste.id}" assignTo="{!postid2}" />
                                </apex:commandButton>
                            </apex:column>
                        </apex:pageBlockTable>
                    </apex:outputpanel>
                </apex:PageBlockSectionItem>
                <apex:pageBlockSectionItem rendered="{!flagItem}">
                    <apex:outputPanel id="leblock2">
                        <apex:pageblocksection title="Radar PID" columns="1">
                            <apex:chart name="myChart" height="400" width="600" legend="false" data="{!data1}">
                                <apex:legend position="bottom" />
                                <apex:axis type="Radial" position="radial" minimum="0" maximum="{!maxim}">
                                    <apex:chartLabel display="insideEnd" font="5px Helvetica, sans-serif" minMargin="0" />
                                </apex:axis>
                                <apex:radarSeries xField="field" yField="value" tips="true" opacity="0.4" markerType="cross" strokeWidth="2" id="idd" title="Validé Manager">
                                    <apex:chartLabel display="none" />
                                    <apex:chartTips rendererFn="rendmnt" />
                                </apex:radarSeries>
                                <apex:radarSeries xField="field" yField="prevue" tips="true" opacity="0.3" markerType="cross" strokeWidth="2" title="Prevue">
                                    <apex:chartLabel display="none" />
                                    <apex:chartTips rendererFn="rendmnt" />
                                </apex:radarSeries>
                                <apex:radarSeries xField="field" yField="objectif" tips="true" opacity="0.3" markerType="cross" strokeWidth="2" title="Objectif">
                                    <apex:chartLabel display="none" />
                                    <apex:chartTips rendererFn="rendmnt" />
                                </apex:radarSeries>
                            </apex:chart>
                        </apex:pageblocksection>
                        <apex:pageblocksection title="Evolution BP" columns="1">
                            <apex:chart name="Evolution BP" height="400" width="600" data="{!data2}">
                                <apex:legend position="bottom" />
                                <apex:axis type="Numeric" minimum="0" maximum="4" position="left" fields="data1" title="Moy Bilan" grid="true" />
                                <apex:axis type="Category" position="bottom" fields="name" title="" />
                                <apex:lineSeries axis="left" fill="false" xField="name" yField="data1" markerType="cross" markerSize="4" markerFill="#FF0000" />
                            </apex:chart>
                        </apex:pageblocksection>
                    </apex:outputPanel>
                </apex:pageBlockSectionItem>
            </apex:pageBlockSection>
        </apex:pageBlock>
    </apex:form>
</apex:page>

any ideas ?

1 Answer 1

-1

Just a small Idea to debug, add an apex:messages area so the VF-Errors will be displayed.

https://developer.salesforce.com/docs/atlas.en-us.pages.meta/pages/pages_compref_messages.htm

2
  • actually, i have added that before posting the question <apex:pageMessages ></apex:pageMessages> Commented May 23, 2016 at 9:51
  • but it does not work Commented May 23, 2016 at 10:38

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .