CanvasJS react component allows you to customize & change the look and functionality of the graph. Below example shows one such customization where index labels are positioned inside a react pie chart. It also includes react source code that you can try running 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 = { theme: "dark2", animationEnabled: true, exportFileName: "New Year Resolutions", exportEnabled: true, title:{ text: "Top Categories of New Year's Resolution" }, data: [{ type: "pie", showInLegend: true, legendText: "{label}", toolTipContent: "{label}: <strong>{y}%</strong>", indexLabel: "{y}%", indexLabelPlacement: "inside", dataPoints: [ { y: 32, label: "Health" }, { y: 22, label: "Finance" }, { y: 15, label: "Education" }, { y: 19, label: "Career" }, { y: 5, label: "Family" }, { y: 7, label: "Real Estate" } ] }] } 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;
In the above pie chart, indexLabelPlacement is set to inside to place the index labels inside the slice of the pie. You can try setting it to outside to place it outside the slice. Index labels can be formatted to the required string format by using indexLabelFormatter
Note For step by step instructions, follow our React Integration Tutorial