CoreUI React.js wrapper for Chart.js
Explore @coreui/react-chartjs docs & examples »
Report bug
·
Request feature
·
Blog
Status
install:
npm install @coreui/react-chartjs
yarn add @coreui/react-chartjs
import:
import { CChart } from '@coreui/react-chartjs'
or
import {
CChart,
CChartBar,
CChartHorizontalBar,
CChartLine,
CChartDoughnut,
CChartRadar,
CChartPie,
CChartPolarArea,
} from '@coreui/react-chartjs'
props:
className?: string
customTooltips?: boolean
data: ChartData | ((canvas: HTMLCanvasElement) => ChartData)
fallbackContent?: React.ReactNode
getDatasetAtEvent?: (
dataset: InteractionItem[],
event: React.MouseEvent<HTMLCanvasElement>,
) => void
getElementAtEvent?: (
element: InteractionItem[],
event: React.MouseEvent<HTMLCanvasElement>,
) => void
getElementsAtEvent?: (
elements: InteractionItem[],
event: React.MouseEvent<HTMLCanvasElement>,
) => void
height?: number
id?: string
options?: ChartOptions
plugins?: Plugin[]
redraw?: boolean
type: ChartType
width?: number
wrapper?: boolean
usage:
...
class CoreUICharts extends Component {
...
render() {
return (
<CChart
type='line'
data={{
labels: ['January', 'February', 'March', 'April', 'May', 'June', 'July'],
datasets: [
{
label: '2019',
backgroundColor: 'rgba(179,181,198,0.2)',
borderColor: 'rgba(179,181,198,1)',
pointBackgroundColor: 'rgba(179,181,198,1)',
pointBorderColor: '#fff',
pointHoverBackgroundColor: '#fff',
pointHoverBorderColor: 'rgba(179,181,198,1)',
tooltipLabelColor: 'rgba(179,181,198,1)',
data: [65, 59, 90, 81, 56, 55, 40]
},
{
label: '2020',
backgroundColor: 'rgba(255,99,132,0.2)',
borderColor: 'rgba(255,99,132,1)',
pointBackgroundColor: 'rgba(255,99,132,1)',
pointBorderColor: '#fff',
pointHoverBackgroundColor: '#fff',
pointHoverBorderColor: 'rgba(255,99,132,1)',
tooltipLabelColor: 'rgba(255,99,132,1)',
data: [28, 48, 40, 19, 96, 27, 100]
}
],
}}
options={{
aspectRatio: 1.5,
tooltips: {
enabled: true
}
}}
/>
)
}
...