#Mantine Charts Legends Mouse-Events don't trigger

6 messages · Page 1 of 1 (latest)

stark light
#

Currently testing out the Charts and I noticed I can't seem to get any event triggered by Interacting with the Legends. Is there anything else I need to due to get them to trigger correctly?

import { LineChart } from "@mantine/charts";
import { Box } from "@mantine/core";
import { ReferenceArea, ReferenceLine } from "recharts";

const data = [
  { id: 1, val1: 1, val2: 5 },
  { id: 2, val1: 2, val2: 6 },
  { id: 3, val1: 3, val2: 7 },
  { id: 4, val1: 4, val2: 8 },
  { id: 5, val1: 5, val2: 9 },
  { id: 6, val1: 6, val2: 10 },
];

function Charts() {
  return (
  <Box h={600} w={"100%"}>
    <LineChart
      mt={20}
      h={"100%"}
      data={data}
      withLegend
      legendProps={{
        verticalAlign: "bottom",
        onMouseDown: () => {
          console.log("onMouseDown");
        },
        onClick: () => {
          console.log("clicked");
        },
        onMouseOver: () => {
          console.log("onMouseOver");
        },
      }}
      dataKey="id"
      series={[
        { name: "val1", color: "red.9" },
        { name: "val2", color: "blue.8" },
      ]}
    >
      <ReferenceLine y={3} stroke="red" />
      <ReferenceArea
        x1={1}
        x2={4}
        y1={1}
        y2={3}
        stroke="red"
        fillOpacity={0.1}
      />
    </LineChart>
  </Box>
  );
}
glacial rampart
stark light
#

Okay makes sense, I was just surprised, that the regular OnClick (and other mouse events) of the Legend-Component seem to get overridden by the default content. Wouldn't it make more sense to use those Legends props in the default content in case that gets renderd?

#

i.e. Changing this such that legendsProps.(onClick, onMouseMove, ...) get passed to the ChartLegend so that they still trigger as expected

stark light
glacial rampart