Update value of pie chart from span - Javascript Chart.js

Javascript examples for Chart.js:Pie Chart

Description

Update value of pie chart from span

Demo Code

ResultView the demo in separate window

<html>
   <head> 
      <meta name="viewport" content="width=device-width, initial-scale=1"> 
      <script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script> 
      <script type="text/javascript" src="https://rendro.github.io/easy-pie-chart/javascripts/jquery.easy-pie-chart.js"></script> 
      <script type="text/javascript">
    window.onload=function(){/*from w  ww  .  java 2 s .  c  o m*/
    $('.percentage').attr('data-percent', $('.newValue').html());
    $('.percentage').easyPieChart({
      animate: 1000,
      lineWidth: 8,
      barColor: '#00aeef',
      scaleColor: 'transparent',
      onStep: function(value) {
        this.$el.find('span').text(Math.round(value));
      },
      onStop: function(value, to) {
        this.$el.find('span').text(Math.round(to));
      }
    });
    }

      </script> 
   </head> 
   <body> 
      <ul> 
         <li>
            <span class="newValue">25</span>
         </li> 
         <li> 
            <div class="pieCharts"> 
               <div class="chart"> 
                  <div class="percentage" data-percent="100">
                     <span>0</span>
                     <sup>%</sup>
                  </div> 
               </div> 
            </div> 
         </li> 
      </ul>  
   </body>
</html>

Related Tutorials