简体   繁体   中英

external page Morris charts not loading when am loading graph page using jquery load event

I want to load DONUT CHART from another page to current page. - some more expiation when i click on button of home page i want to dispaly chart of graph-page.php

Note: when i manually run Graph_page.php it's working fine

Home.php

<input class="button" type="button" />
     <div class="home"></div>

       <script>
        $(document).ready(function(){
         $(".button").click(function(){
         $(".home").load("Graph_page.php", function(responseTxt, statusTxt, xhr){
          if(statusTxt == "success")
           //success alert

           if(statusTxt == "error")
         //error alert
    });

   });

  });
   </script>

Graph_page.php

       <div class="box-body chart-responsive">
   <div class="chart" id="sales-chart" position: relative;"></div>
          </div>

//script DONUT CHART
 <script type="text/javascript">
  $(function () {
    "use strict";      
    var donut = new Morris.Donut({
      element: 'sales-chart',
      resize: true,
      colors: ["#f56954","#00a65a","#3c8dbc"],
      data: [
        {label: "Absent Days", value: 5},
        {label: "Present Days", value: 10}, 
        {label: "Working Days", value: 15}
      ],
      hideHover: 'auto'
    });

  });
</script>

The best way for this

$(".home").load("Graph_page.php", function(responseTxt, statusTxt, xhr){     
var donut = new Morris.Donut({
  element: 'sales-chart',
  resize: true,
  colors: ["#f56954","#00a65a","#3c8dbc"],
  data: [
    {label: "Absent Days", value: 5},
    {label: "Present Days", value: 10}, 
    {label: "Working Days", value: 15}
  ],
  hideHover: 'auto'
});

The Morris builder does not recognize the recent loaded DOM, so this build after load the page.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM