Our react charts come with Index Labels that can be utilized to display additional data on top of dataPoints like x value, y value or any custom string. Likewise it can be utilized to feature any information of uncommon intrigue. Index Labels are bolstered by all graphs in React Charting Library including line, area, donut, bar, and so on. Given illustration indicates most elevated information point 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: "light2", //"light1", "dark1", "dark2" title:{ text: "Simple Column Chart with Index Labels" }, axisY: { includeZero: true }, data: [{ type: "column", //change type to bar, line, area, pie, etc //indexLabel: "{y}", //Shows y value on all Data Points indexLabelFontColor: "#5A5757", indexLabelPlacement: "outside", dataPoints: [ { x: 10, y: 71 }, { x: 20, y: 55 }, { x: 30, y: 50 }, { x: 40, y: 65 }, { x: 50, y: 71 }, { x: 60, y: 68 }, { x: 70, y: 38 }, { x: 80, y: 92, indexLabel: "Highest" }, { x: 90, y: 54 }, { x: 100, y: 60 }, { x: 110, y: 21 }, { x: 120, y: 49 }, { x: 130, y: 36 } ] }] } return ( <div> <CanvasJSChart options = {options} /* onRef={ref => this.chart = ref} */ /* containerProps={{ width: '100%', height: '300px' }} */ /> {/*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 chart, Index Labels are used to depict the highest value. You can customize the Index Labels using various options like indexLabelOrientation, indexLabelFormatter, indexLabelMaxWidth.
Note For step by step instructions, follow our React Integration Tutorial