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

Custom legend in line chart is not rendering. #2642

Closed
scio-cypher opened this issue Aug 26, 2024 · 2 comments
Closed

Custom legend in line chart is not rendering. #2642

scio-cypher opened this issue Aug 26, 2024 · 2 comments

Comments

@scio-cypher
Copy link

scio-cypher commented Aug 26, 2024

Legend in axisBottom prop of Line Chart seems to accept ReactNode but whenever I try to provide with

tag, the content doesn't renders.

Here's code of how I'm doing it.

<ResponsiveLine data={lineData} margin={{ top: 10, right: 20, bottom: 100, left: 60 }} colors={({ id }) => lineColors[id] || "black"} xScale={{ type: 'point' }} yScale={{ type: 'linear', min: 'auto', max: 'auto', stacked: false, reverse: false }} enableSlices="x" axisTop={null} axisRight={null} axisBottom={{ tickSize: 9, tickPadding: 2, tickRotation: 0, legend: 'transportation', legendOffset: 36, legendPosition: 'middle', truncateTickAt: 0 }} axisLeft={{ tickSize: 5, tickPadding: 5, tickRotation: 0, legend: <div>Legend text</div>, //This ain't working legendOffset: -40, legendPosition: 'middle', truncateTickAt: 0 }} curve="natural" pointSize={7} pointColor={{ theme: 'labels.text.fill' }} pointBorderWidth={7} pointBorderColor={{ from: 'serieColor' }} pointLabel="data.yFormatted" pointLabelYOffset={-12} enableGridX={true} enableGridY={true} enablePoints={true} enablePointLabel={true} enableArea={false} lineWidth={2} legends={[]} isInteractive={true} tooltip={() => {}} enableCrosshair={true} crosshairType="cross" enableTouchCrosshair={true} useMesh={true} sliceTooltip={renderTooltip} layers={["areas", "axes", "crosshair", "grid", "legends", "lines", "markers", "mesh", "points", "slices"]} />

You can see in the axisLeft prop I'm trying to pass my element to legend key, but it doesn't renders anything.

Thank you in advanced!

@annshiv
Copy link

annshiv commented Sep 1, 2024

Nivo Line charts do not support passing a ReactNode to the legend property directly; it only supports string. Use a plain string for the legend.

@plouc
Copy link
Owner

plouc commented Oct 20, 2024

@annshiv is right, it only supports a string as the implementation can be either SVG or canvas.
On a side note, please format your code when submitting issues, thank you.

@plouc plouc closed this as completed Oct 20, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants