Animation makes visualization more appealing. CanvasJS React component supports rendering of all available charts with animation. Below example shows animated pie chart in react alongside source code that you can run locally.
/* App.js */ import React, { Component } from 'react'; import CanvasJSReact from '@canvasjs/react-charts'; //var CanvasJSReact = require('@canvasjs/react-charts'); var CanvasJS = CanvasJSReact.CanvasJS; var CanvasJSChart = CanvasJSReact.CanvasJSChart; class App extends Component { render() { const options = { animationEnabled: true, exportEnabled: true, theme: "dark2", // "light1", "dark1", "dark2" title:{ text: "Trip Expenses" }, data: [{ type: "pie", indexLabel: "{label}: {y}%", startAngle: -90, dataPoints: [ { y: 20, label: "Airfare" }, { y: 24, label: "Food & Drinks" }, { y: 20, label: "Accomodation" }, { y: 14, label: "Transportation" }, { y: 12, label: "Activities" }, { y: 10, label: "Misc" } ] }] } return ( <div> <CanvasJSChart options = {options} /* onRef={ref => this.chart = ref} */ /> {/*You can get reference to the chart instance as shown above using onRef. This allows you to access all chart properties and methods*/} </div> ); } } export default App;
Animation duration can be controlled by setting required duration to animationDuration property. The data points can be exploded by setting exploded property to true in charts like pie, doughnut, funnel, pyramid.
Note For step by step instructions, follow our React Integration Tutorial