Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- initPieChart: function (id, title, sub, footer, values, labelOrQtd){
- var dataPieChart = {
- series: [160, 60],
- labels: ['', '']
- };
- var optionsPieChart = {
- donut: true,
- donutWidth: 20,
- startAngle: 210,
- total: 260,
- showLabel: false,
- plugins: [
- [
- Chartist.plugins.fillDonut({
- items: [{
- content: '<i class="fa fa-tachometer text-muted"></i>',
- position: 'bottom',
- offsetY: 10,
- offsetX: -2
- }, {
- content: '<h3>80<span class="small">%</span></h3>'
- }]
- })
- ]
- ]
- };
- var end = '#' + id;
- var pieChart = new Chartist.Pie(end, dataPieChart, optionsPieChart);
- //start animation for the Bar Chart
- md.startAnimationForPieChart(pieChart);
- }
- startAnimationForPieChart: function (chart) {
- chart.on('draw', function (data) {
- if (data.type === 'slice' && data.index == 0) {
- // Get the total path length in order to use for dash array animation
- var pathLength = data.element._node.getTotalLength();
- // Set a dasharray that matches the path length as prerequisite to animate dashoffset
- data.element.attr({
- 'stroke-dasharray': pathLength + 'px ' + pathLength + 'px'
- });
- // Create animation definition while also assigning an ID to the animation for later sync usage
- var animationDefinition = {
- 'stroke-dashoffset': {
- id: 'anim' + data.index,
- dur: 1200,
- from: -pathLength + 'px',
- to: '0px',
- easing: Chartist.Svg.Easing.easeOutQuint,
- // We need to use `fill: 'freeze'` otherwise our animation will fall back to initial (not visible)
- fill: 'freeze'
- }
- };
- // We need to set an initial value before the animation starts as we are not in guided mode which would do that for us
- data.element.attr({
- 'stroke-dashoffset': -pathLength + 'px'
- });
- // We can't use guided mode as the animations need to rely on setting begin manually
- // See http://gionkunz.github.io/chartist-js/api-documentation.html#chartistsvg-function-animate
- data.element.animate(animationDefinition, true);
- }
- });
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement