Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[charts] Pie chart tooltip runtime warning #11679

Closed
ledevinchi opened this issue Jan 14, 2024 · 23 comments
Closed

[charts] Pie chart tooltip runtime warning #11679

ledevinchi opened this issue Jan 14, 2024 · 23 comments
Labels
component: charts This is the name of the generic UI component, not the React module!

Comments

@ledevinchi
Copy link

ledevinchi commented Jan 14, 2024

Steps to reproduce

Hi,
i'm using MUI-Charts pie chart.
on runtime, when the tooltip is active (hovering above the chart) i get a warning:

Warning: Failed prop type: Invalid prop 'series.data[0]' of type 'object' supplied to 'DefaultChartsItemTooltipContent', expected 'number'.

here is part of my code:
<PieChart series={[ { data: testData, valueFormatter(item) { return '$' + item.value.toFixed(2); }, }, ]} slotProps={{ legend: { hidden: true } }} width={400} height={200} />

the testData is {id: number, label: string, value: number, color: string}, no nulls.

by trying to fix the problem i changed the testData to be an array of number, but then i get a syntax error.
i read the documentation and didn't find anything to fix it.

THE CODE IS WORKING but i can't get rid of the warning.
any ideas?

Current behavior

No response

Expected behavior

No response

Context

No response

Your environment

npx @mui/envinfo
  Don't forget to mention which browser you used.
  Output from `npx @mui/envinfo` goes here.

Search keywords: tooltip runtime warning

@ledevinchi ledevinchi added the status: waiting for maintainer These issues haven't been looked at yet by a maintainer label Jan 14, 2024
@michelengelen michelengelen changed the title Mui charts -Pie chart tooltip runtime warning [charts] Pie chart tooltip runtime warning Jan 15, 2024
@michelengelen
Copy link
Member

Hi @ledevinchi,

Please provide a minimal reproduction test case with the latest version. This would help a lot 👷.

A live example would be perfect. This codesandbox.io template may be a good starting point. You can find more codesandbox templates in our docs.

Thank you! 🙇🏼

@michelengelen michelengelen added status: waiting for author Issue with insufficient information component: charts This is the name of the generic UI component, not the React module! and removed status: waiting for maintainer These issues haven't been looked at yet by a maintainer labels Jan 15, 2024
@alexfauquette alexfauquette removed the status: waiting for author Issue with insufficient information label Jan 15, 2024
@alexfauquette
Copy link
Member

For a reason I ignore the Proptypes generated have a series with data as an array of number, but type can be pie. Still need to investigate to see if it's a TS error or if the proptypes generator has an issue

series: PropTypes.shape({
    color: PropTypes.string,
    data: PropTypes.arrayOf(PropTypes.number).isRequired,
    highlightScope: PropTypes.shape({
      faded: PropTypes.oneOf(['global', 'none', 'series']),
      highlighted: PropTypes.oneOf(['item', 'none', 'series']),
    }),
    id: PropTypes.string.isRequired,
    type: PropTypes.oneOf(['bar', 'line', 'pie', 'scatter']).isRequired,
    valueFormatter: PropTypes.func.isRequired,
  }).isRequired,

@ledevinchi
Copy link
Author

Hi,
the 'data' type @alexfauquette showed is different then what i get in my code.
i get (property) data: MakeOptional<PieValueType, "id">[]
instead of
data: PropTypes.arrayOf(PropTypes.number).isRequired,.

forgot to mention i'm using next v13.5.6 (Typescript)
charts v6.18.7
mui/material v5.15.4

@alexfauquette
Copy link
Member

alexfauquette commented Jan 15, 2024

@ledevinchi Yes, The typing seems ok. We have a script that generate proptypes to avoid maintaining TS and Proptypes. But seems it does not support well nested unions.

I reproduced the error in a test. Will see if I succeed to make it pass 😁
mui/material-ui#40617

A quick solution could be to remove those proptypes for now to avoid having a useless error message 🤔

@michaldudak
Copy link
Member

A just-as-quick and more correct solution would be to update the proptype manually and add the /* @typescript-to-proptypes-ignore */ annotation, so it won't be overridden.

@ledevinchi
Copy link
Author

i'm kind of new to the industry, what next? is something that is going to be fix in the next version or where should i use @michaldudak /* @typescript-to-proptypes-ignore */?

@alexfauquette
Copy link
Member

alexfauquette commented Jan 17, 2024

It's something that needs to be fixed on our side and will be available in following version. When the fix is done, this issue will be closed, and you will get the fix in the version coming after the issue closed (usualy on thursday)

@konrad-jamrozik
Copy link

konrad-jamrozik commented Jan 21, 2024

I am running into something similar with a very simple LineChart. I get following console warning in Chrome DevTools:

console.js:213 Warning: Failed prop type: Invalid prop `axis.scaleType` of value `linear` supplied to `DefaultChartsAxisTooltipContent`, expected one of ["time"].

Chart def.:

<LineChart
  xAxis={[
    {
      data: [1, 2, 3],
    },
  ]}
  series={[
    {
      data: [1, 2, 3],
    },
  ]}
  width={500}
  height={300}
/>

npm ls (irrelevant rows omitted):

Full stack trace:

chunk-BX4QH3UP.js?v=5bcdf0c4:64 Warning: Failed prop type: Invalid prop `axis.scaleType` of value `linear` supplied to `DefaultChartsAxisTooltipContent`, expected one of ["time"].
    at DefaultChartsAxisTooltipContent 
    at ChartsAxisTooltipContent 
    at div
    at PopperTooltip2 
    at Portal2 
    at Popper2 
    at 
    at NoSsr 
    at ChartsTooltip 
    at svg
    at 
    at ChartsSurface2 
    at HighlightProvider 
    at InteractionProvider 
    at CartesianContextProvider 
    at SeriesContextProvider 
    at DrawingProvider 
    at ChartContainer2 
    at div
    at 
    at ResponsiveChartContainer2 
    at LineChart2 
    at PrototypeChart 
    at span
    at 
    at Typography2 
    at div
    at 
    at Box3 
    at div
    at 
    at Container3 
    at App 
    at ThemeProvider2 

Looking here:

https://mui.com/x/api/charts/default-charts-axis-tooltip-content/#props

I see:

image

I guess other values than time should be supported?

@xorgal
Copy link

xorgal commented Jan 21, 2024

I'm having the same issue with PieChart:

Failed prop type: Invalid prop `series.data[0]` of type `object` supplied to `DefaultChartsItemTooltipContent`, expected `number`.

It seems the shape of data is same as described in documentation, not sure what is actually wrong. Here is implementation:

const ScoreChart = ({
  correctAnswers,
  wrongAnswers,
  score,
  width = 150,
  height = 150,
}: ScoreChartProps): JSX.Element => {
  const theme = useTheme();

  const getScoreChartData = (correctAnswers: number, wrongAnswers: number): ChartItem[] => {
    return [
      { value: correctAnswers, label: 'Correct answers' },
      { value: wrongAnswers, label: 'Wrong answers' },
    ];
  };

  const data = useMemo(() => {
    return getScoreChartData(correctAnswers, wrongAnswers);
  }, [correctAnswers, wrongAnswers]);

  return (
    <PieChart
      series={[{ data, innerRadius: 50, outerRadius: 70 }]}
      width={width}
      height={height}
      sx={{ border: 0 }}
      margin={{ top: 0, bottom: 0, left: 0, right: 0 }}
      slotProps={{
        legend: {
          hidden: true,
          direction: 'row',
          position: {
            vertical: 'bottom',
            horizontal: 'middle',
          },
        },
      }}
      colors={[theme.palette.success.main, theme.palette.error.main]}
    >
      <ScoreLabel>{score.toFixed(0)}</ScoreLabel>
    </PieChart>
  );
};

As a temporary workaround I'm casting slice() method and error is not popping up anymore:

 series={[{ data: data.slice(), innerRadius: 50, outerRadius: 70 }]}

Dependencies:

@mui/material 5.15.5
@mui/system 5.15.5
@mui/x-charts 6.19.1
@emotion/styled 11.11.0
@emotion/cache 11.11.0
@emotion/react 11.11.3
react 18.2.0
react-dom 18.2.0

@dbuhon
Copy link

dbuhon commented Jan 30, 2024

It is reproducible on the codesandbox example from the official doc.
When hovering over the chart the following warning appears in the console:

Warning: Failed prop type: Invalid prop `series.data[0]` of type `object` supplied to `DefaultChartsItemTooltipContent`, expected `number`.

@alexfauquette
Copy link
Member

alexfauquette commented Jan 30, 2024

It's fixed in v7. I still need to cherry pick the modification in v6

It's a bit trickier. The fix is ready. I can't reproduce the bug. But because the fix was done in github.com/mui/material-ui (and bumping the monorepo) We've seen no modification in the changelog and so we did not release a v6.19.2 of the charts.

The fix will be available in 2 days with the next release

@alexfauquette
Copy link
Member

Should be fixed now for both v6.19.3 and v7.0.0-beta.1

@Aqkotz
Copy link

Aqkotz commented Feb 2, 2024

Hi, just updated to v6.19.3 and also tried v7.0.0-beta.1 and getting the same problem, crashes on hover over pie charts and bar charts.

@konrad-jamrozik
Copy link

konrad-jamrozik commented Feb 3, 2024

On mui/[email protected] I am still getting the same problem described in my comment above:

Warning: Failed prop type: Invalid prop `axis.scaleType` of value `linear` supplied to `DefaultChartsAxisTooltipContent`, expected one of ["time"].

@alexfauquette alexfauquette reopened this Feb 5, 2024
@alexfauquette
Copy link
Member

@Aqkotz @konrad-jamrozik
Could you provide a reproduction of the tooltip failing?

For the pie chart, I can see the following error

Warning: Failed prop type: Invalid prop seriesToDisplay[0].id of type number supplied to DefaultChartsLegend, expected string.

Which can be fixed by using string for series ids

However I don't see warning when the tooltip get displayed:

https://stackblitz.com/edit/react-a1vkus?file=Demo.tsx

bug_ttoltip.mp4.webm

@konrad-jamrozik
Copy link

konrad-jamrozik commented Feb 5, 2024

@alexfauquette Apologies, looks like there is no problem after all.

I was trying to reproduce the issue on a new machine and I am unable to. The problem appears only on the older version of relevant MUI package. Looks like this was perhaps local caching issue on my part, sorry about that! Later today (in about 10 hours) I will double-check on my primary dev machine if it behaves the same way, but I fully expect that.

@Aqkotz
Copy link

Aqkotz commented Feb 5, 2024

@alexfauquette I changed the ids to strings, but still get this error when I hover the pie chart. I've cleared the npm cache and updated to 6.19.3.

TypeError: Cannot read properties of undefined (reading 'create') at @mui_x-charts_PieChart.js?v=08a2d3ef:11149:33 at muiStyledFunctionResolver (chunk-BQI326TR.js?v=b67161f0:7356:30) at transformedStyleArg (chunk-BQI326TR.js?v=b67161f0:7198:42) at handleInterpolation (chunk-BQI326TR.js?v=b67161f0:2654:22) at serializeStyles2 (chunk-BQI326TR.js?v=b67161f0:2817:19) at chunk-BQI326TR.js?v=b67161f0:3522:28 at chunk-BQI326TR.js?v=b67161f0:2907:16 at renderWithHooks (chunk-GSZ7ISAW.js?v=b67161f0:12171:26) at updateForwardRef (chunk-GSZ7ISAW.js?v=b67161f0:14327:28) at beginWork (chunk-GSZ7ISAW.js?v=b67161f0:15934:22)

@alexfauquette
Copy link
Member

@Aqkotz Your error is unreleated to this issue. It's not a proptypes error. Coudl you open an issue with a reproduction example either in codesandbox or stackblitz such that I can reproduce and debug it?

image

@konrad-jamrozik Thanks for confirmation. I let you close this issue it it works on your other computer, or report the error if it does not 👍

@enlznep
Copy link

enlznep commented Feb 6, 2024

@alexfauquette
Copy link
Member

@enlznep No, this one is another one that will need a distinct fix, because it's the TS definition which is wrong

@enlznep
Copy link

enlznep commented Feb 6, 2024

@alexfauquette I see. Is this ticket going to be enough to track the fixes for dataset or we have a separate issue for that?

@alexfauquette
Copy link
Member

That's enough. This PR #11953 should solve it 👍

I was puzzled because I spoted and fixed it on v7 but forgot to back port it to v6

@konrad-jamrozik
Copy link

konrad-jamrozik commented Feb 7, 2024

@alexfauquette I've checked on another machine and the problem I mentioned is indeed absent. Thank you for the quick fix! Much appreciated! ❤️

(note I don't have permissions to close this issue myself)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
component: charts This is the name of the generic UI component, not the React module!
Projects
None yet
Development

Successfully merging a pull request may close this issue.

9 participants