chartist icon indicating copy to clipboard operation
chartist copied to clipboard

Chartist line graphs animation starts from the bottom

Open NekoLopez opened this issue 6 years ago • 2 comments

I'm using Chartist.js to generate line graphs, It works great, but I notice lines animation starts at the beginning in a certain height from chart bottom by default:

opos

How can I modify my code to start lines animation from the bottom of the chart like this:

opos2

This is my code:

function graph(month,shop,sale){
  var data = {         
    labels: month,          
    series: [sale,shop]
    };

var options = {
  fullWidth:true,
  height: 380, 
  showPoint: true,
  low: 0,
  showArea: true,
  lineSmooth: false,
  plugins: [
      Chartist.plugins.legend({
          legendNames: ['Sale', 'Shop'],
      })
  ]
};

var chart = new Chartist.Line('.ct-chart', data, options);

chart.on('draw', function(data) {
  if(data.type === 'point') {
    var circle = new Chartist.Svg('circle', {
      cx: [data.x], cy:[data.y], r:[5],
    }, 'ct-circle');
    data.element.replace(circle);
  }
});

   chart.on('draw', function(data) {
     if(data.type === 'line' || data.type === 'area') {
       data.element.animate({
         d: {
            begin: 1000 * data.index,
            dur: 1000,
            from: data.path.clone().scale(1, 0).translate(0, data.chartRect.height()).stringify(),
             to: data.path.clone().stringify(),
              easing: Chartist.Svg.Easing.easeOutQuint
          }
        });
      }
   });      
}

var data = {         
  labels: ['Enero', 'Febrero', 'Marzo','Abril','Mayo','Junio']
 };

 var options = {
    fullWidth:true,
    height: 380
 };

 new Chartist.Line('.ct-chart', data, options);

 $(document).ready(function(){
     $.ajax({
         url: "myfile.php",
         type: "GET",
         dataType: "json",
         success: function(resp)
         {
              var month = resp[0];
              var shop = resp[1];
              var sale = resp[2]; 
             graph(month,shop,sale);
        }
     });
  });

NekoLopez avatar May 22 '18 21:05 NekoLopez

instead of using translate(0, data.chartRect.height()) use translate(0, data.chartRect.y1)

rumansaleem avatar Aug 12 '18 06:08 rumansaleem

Hello @NekoLopez 👋

Chartist has recently been updated to version 1.0 with some new exciting changes like ESM and TypeScript support. The migration guide can be found right here.

Please let me know if the issue is still relevant to you so we can further investigate it!

Arantiryo avatar Oct 29 '22 10:10 Arantiryo