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

Can it support animation #33

Open
ghost opened this issue Jan 12, 2016 · 5 comments
Open

Can it support animation #33

ghost opened this issue Jan 12, 2016 · 5 comments

Comments

@ghost
Copy link

ghost commented Jan 12, 2016

First. I use this component very long. it's amazing.
However. I wish we use it can show a animation with chart.
So. How do i do it.
Thx .

@TonyFrancis
Copy link

yes
Give a new props to it listener

   <ChartistGraph key="1" className="ct-chart-line" data={{  labels: ["foo","bar"], series:[ [1,2,3],[3,4,5]]  }}  type={'Line'} listener={{"draw" : function(data) {
  if(data.type === 'line' || data.type === 'area') {
    data.element.animate({
      d: {
        begin: 2000 * data.index,
        dur: 2000,
        from: data.path.clone().scale(1, 0).translate(0, data.chartRect.height()).stringify(),
        to: data.path.clone().stringify(),
        easing: Chartist.Svg.Easing.easeOutQuint
      }
    });
  } } }}/>

@raptoria
Copy link

raptoria commented Jun 19, 2016

How do I make the bars animate it if I am passing new data to the chart via props every time a button is clicked? (not triggering the 'draw' function)

eg. in parent component I have:

import HBar from '../components/Chart/HorizontalChart';

      <HBar data={this.state.votes} /> 

HorizontalChart.jsx

      import React, {Component} from 'react';
      import ReactDOM from 'react-dom';
      import ChartistGraph from 'react-chartist';
      import styles from 'style!./chartist.css';

      export default class HorizontalChart extends Component {

        static propTypes = {
          data: React.PropTypes.object,
        }

        render() {

          let { data } = this.props;
          let options = {
            seriesBarDistance: 10,
            reverseData: true,
            high:20,
            low:0,
            horizontalBars: true,
            axisY: {
              offset: 70
            }
          };
          let type = 'Bar'

          return (
            <div> 
            <ChartistGraph data={data} options={options} type={type} />
            </div>
          )
        }
      }

@ellenschwartau
Copy link

ellenschwartau commented Aug 1, 2016

I animated bars by setting this as listener:

<ChartistGraph  ... listener={{"draw" : function(data) { if(data.type === 'bar') {
                data.element.animate({
                  y2: {
                      begin: 0,
                      dur: 500,
                      from: data.y1,
                      to: data.y2,
                      easing: Chartist.Svg.Easing.easeOutSine,
                  }});
}}}/>

@larrybotha
Copy link

Because you're relying on the Chartist library directly, importing it will by default import it twice into your compiled js if you're using Webpack.

Make sure to alias chartist so that Webpack resolves React-Chartist's Chartist and your Chartist:

// webpack.config.js
...
  resolve: {
    alias: {
      ...
      chartist: path.resolve(__dirname, 'node_modules/chartist'),
      ...
    },
  },
...

@lim1017
Copy link

lim1017 commented Mar 17, 2020

Does anyone have a pie chart animation?
Ive looked over the above posts, but I really have no idea how animations works

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

5 participants