Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
463 views
in Technique[技术] by (71.8m points)

twig - Change the google graph value using AJAX

My controller :

$pieDemandeStatut = new PieChart();
    $pieDemandeStatut->getData()->setArrayToDataTable(            
        [[]]       
    );

    if(isset($_GET['value_equipe'])) {
        $value = $_GET['value_equipe'];
        
        $pieDemandeStatut = new PieChart();
        $pieDemandeStatut->getOptions()->setTitle('Demandes par Statut');

        $em = $this->getDoctrine()->getManager();
        $statuts = $em->getRepository('AppBundle:Statut')->findAll();
        $query = $em->createQuery('
            SELECT e.nom as equipe, count(a) as total from AppBundle:Affectation a
            JOIN AppBundle:Equipe e
            WHERE e.id = '.$value.'
            
            GROUP By equipe
            
        ');
        $demandes_equipe = $query->getResult();
        
        //$statut_data = array(array());
        $equipe_data = [['hamid',2]];
        //array_push($stack, "apple", "raspberry");
        foreach ($demandes_equipe as $demande){
            array_push($equipe_data, [$demande['equipe'],(int)$demande['total']]);
        }   
        $pieDemandeStatut->getData()->setArrayToDataTable(
                
            $equipe_data
                
        );
        return $this->render('default/index.html.twig',array('demandes' => $demandes,
        'users' => $users,
        'equipes' => $equipes,
        'injections' => $injections,
        'piechart' => $pieChart,
        'pieDemandeStatut' => $pieDemandeStatut));
    
    }
    
    return $this->render('default/index.html.twig', [
        'demandes' => $demandes,
        'users' => $users,
        'equipes' => $equipes,
        'injections' => $injections,
        'piechart' => $pieChart,
        'pieDemandeStatut' => $pieDemandeStatut

    ]);

My view:

<script>
    
    $('#equipe').on('change', function() {
        var value_equipe = this.value;
        var url = window.location.href;  
       $.ajax({
            url: "{{ path('homepage') }}",  
            type: 'GET',
            data: {value_equipe: value_equipe},
            

                success : function(response_data) {  
                    alert(response_data)
                    {{ gc_draw([pieDemandeStatut], ['div_pieDemandeStatutchart']) }}
                } 
        }); 
    });

I want to change the google graph view on every select change. But it sticks to the first value of my "PieDemandeStatut".

The idea is to get the status for every team. The user select the team and it gives him the chart of the status

I searched in other members problem that look similar to this and I found out that twig doesn't get changed on AJAX success.

question from:https://stackoverflow.com/questions/65888618/change-the-google-graph-value-using-ajax

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

1.4m articles

1.4m replys

5 comments

57.0k users

...