import React, { useState, useContext } from 'react'; import { Row, Col, Card, CardBody, CustomInput } from 'reactstrap'; import { Line } from 'react-chartjs-2'; import { rgbaColor, themeColors, isIterableArray } from '../../../helpers/utils'; import AppContext from '../../../context/Context'; const LineChart = ({ reportingTitle, baseTitle, labels, data, options }) => { const [selectedLabel, setSelectedLabel] = useState('a0'); const [option, setOption] = useState('a0'); const { isDark } = useContext(AppContext); const config = { data(canvas) { const ctx = canvas.getContext('2d'); const gradientFill = isDark ? ctx.createLinearGradient(0, 0, 0, ctx.canvas.height) : ctx.createLinearGradient(0, 0, 0, 250); gradientFill.addColorStop(0, isDark ? 'rgba(44,123,229, 0.5)' : 'rgba(255, 255, 255, 0.3)'); gradientFill.addColorStop(1, isDark ? 'transparent' : 'rgba(255, 255, 255, 0)'); return { labels: labels[selectedLabel], datasets: [ { borderWidth: 2, data: data[option], borderColor: rgbaColor(isDark ? themeColors.primary : '#000', 0.8), backgroundColor: gradientFill } ] }; }, options: { legend: { display: false }, tooltips: { mode: 'x-axis', xPadding: 20, yPadding: 10, displayColors: false, callbacks: { label: tooltipItem => `${labels[selectedLabel][tooltipItem.index]} - ${tooltipItem.yLabel}`, title: () => null } }, hover: { mode: 'label' }, scales: { xAxes: [ { ticks: { fontColor: rgbaColor('#789', 0.8), fontStyle: 600 }, gridLines: { color: rgbaColor('#000', 0.1), zeroLineColor: rgbaColor('#000', 0.1), lineWidth: 1 } } ], yAxes: [ { display: true, gridLines: { color: rgbaColor('#000', 0.1) } } ] } } }; return (

{reportingTitle}

{baseTitle}

{isIterableArray(options) && {setOption(target.value); setSelectedLabel(target.value);}} > {options.map(({ value, label }) => ( ))} }
); }; export default LineChart;