recharts#ReferenceDot TypeScript Examples
The following examples show how to use
recharts#ReferenceDot.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: Chart.tsx From crypto-fees with MIT License | 4 votes |
Chart: React.FC<SeriesChartProps> = ({
data,
primary,
secondary,
loading,
protocols,
server,
events,
}) => {
const [tooltip, setTooltip] = useState<null | ActiveTooltip>(null);
const color = 'blue';
const textColor = 'black';
const Container: any = server ? 'div' : ResponsiveContainer;
const margin = server
? { top: 20, right: 20, bottom: 20, left: 20 }
: { top: 0, right: 10, bottom: 6, left: 0 };
const width = server ? 380 : 500;
return (
<Container height={200}>
<LineChart height={200} width={width} margin={margin} barCategoryGap={1} data={data}>
<XAxis
tickLine={false}
stroke="#efefef"
interval="preserveStartEnd"
tickMargin={14}
minTickGap={0}
tickFormatter={(tick: any) => toNiceDate(tick)}
dataKey="date"
tick={{ fill: textColor }}
type={'number'}
domain={['dataMin', 'dataMax']}
/>
<YAxis
type="number"
orientation="right"
tickFormatter={(tick: any) => '$' + toK(tick)}
stroke="#efefef"
interval="preserveEnd"
minTickGap={80}
yAxisId={0}
tickMargin={16}
tick={{ fill: textColor }}
/>
<Tooltip
cursor={true}
separator={tooltip ? null : ' : '}
formatter={(val: any) => (tooltip ? [tooltip.description] : formattedNum(val))}
labelFormatter={(label: any) => toNiceDateYear(label)}
labelStyle={{ paddingTop: 4 }}
position={tooltip?.point}
contentStyle={{
padding: '10px 14px',
borderRadius: 10,
borderColor: color,
color: 'black',
maxWidth: 250,
whiteSpace: 'normal',
}}
wrapperStyle={{ top: -70, left: -10 }}
/>
<Line
strokeWidth={2}
dot={false}
type="monotone"
name={protocols[primary]}
dataKey="primary"
yAxisId={0}
stroke="#f2a900"
/>
{events?.map((event) => (
<ReferenceDot
key={event.description}
x={dateToTimestamp(event.date)}
y={findFee(data, dateToTimestamp(event.date))}
r={4}
fill="#b957af"
onMouseOver={(e: any) =>
setTooltip({
description: event.description,
point: { x: e.cx + 10, y: e.cy - 10 },
})
}
onMouseOut={() => setTooltip(null)}
/>
))}
{secondary && (
<Line
strokeWidth={2}
dot={false}
type="monotone"
name={protocols[secondary]}
dataKey="secondary"
yAxisId={0}
stroke="#d6d3cc"
/>
)}
{loading && <rect height="100%" width="100%" opacity="0.5" fill="#666" />}
</LineChart>
</Container>
);
}