Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update chart in twig template after AJAX request not displaying #42

Open
Luka2010 opened this issue May 11, 2020 · 1 comment
Open

Update chart in twig template after AJAX request not displaying #42

Luka2010 opened this issue May 11, 2020 · 1 comment

Comments

@Luka2010
Copy link

Luka2010 commented May 11, 2020

I try since weeks to update the chart via an AJAX request. I use tabs which send of the AJAX request
In my normal view I have the following function:

$('#country-tabs a').on('click', function (e) {
         e.preventDefault()
         $(this).tab('show');
         var $this = $(this),
         loadurl = $this.attr('href');

         var form = $('form');
                       
         var jsonData = $.ajax({
             url: loadurl,  
             type:       'POST',
             data: form.serializeArray(),
             dataType:   'json',  
             async: false,

             success: function(data, status) {              
                 $("div#client-loop-container").html(data.chartview); 
                 $('#status').addClass('status-bar-success');
     }
       }).responseText;

     });

My controller then returns

if ($request->isXmlHttpRequest())
       {   
         $result = $this->renderView('fruits/chart.html.twig', [
                 'fruitCounts' => $fruitCounts,
                 'barchart' => $barchart
           ]);
          return new JsonResponse(['success' => true, 'chartview' => $result]);
    }

My chart.twig.html then has the following:

   <div id="client-loop-container">
       <div class="w-100" id="div_chart"></div>
        {{  dump(barchart) }}      
        {% block javascripts %}
            <script type="text/javascript" src="https://www.gstatic.com/charts/loader.js"></script>
           <script type="text/javascript">          
             {{ gc_draw(barchart, 'div_chart') }}
           </script>
       {% endblock %}

dump(barchart) Shows CMEN\GoogleChartsBundle\GoogleCharts\Charts\LineChart with the updated data, but I do not get any Chart displayed. What am I missing here? Is it a bug, do I use it wrong or is it simply not possible to do?

@chekinih
Copy link

I have the same issue

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants