question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Accepting function instead of dataKey

See original GitHub issue

It would be great if it were possible to pass a function that evaluates to a data points value instead of passing a dataKey

i.e.

<Line dataKey="uv" />

could be equivalent to

<Line value={ (data, index) => data[index]["uv"] } />

That would allow Recharts to make less assumptions about the passed datas format and would enable more use cases like computing values

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Reactions:15
  • Comments:28 (5 by maintainers)

github_iconTop GitHub Comments

18reactions
JarLowreycommented, Nov 21, 2017

@erayalakese using a function works for me

//data=[{ ttt: 'a', asd: 12 }, { ttt: 'b', asd: 32 }, { ttt: 'c', asd: 55 },]
	render() {
		let getVal = (x)=>{return x.asd;}
		let getName = (x)=>{return x.ttt;}
		return (
			<LineChart width={730} height={250} data={this.state.data}
				margin={{ top: 5, right: 30, left: 20, bottom: 5 }}>
				<CartesianGrid strokeDasharray="3 3" />
				<XAxis dataKey={getName} />
				<YAxis />
				<Tooltip />
				<Legend />
				<Line type="monotone" dataKey={getVal} stroke="#8884d8" />
			</LineChart>
		);
	}
10reactions
xile611commented, Dec 5, 2016

@tarrencev Thanks! We’ll think about this feature.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Exploring Recharts: different ways of accessing data
Passing data in dataKey helps with some level of customization to ... Accepting function instead of dataKey · Issue #383 · recharts/recharts ...
Read more >
React DataKey in Charts - Stack Overflow
I would add the keys to the chart objects and use them as props inside the Chart component. Like so: const charts =...
Read more >
GenerateDataKeyPair - AWS Key Management Service
GenerateDataKeyPair returns a unique data key pair for each request. The bytes in the keys are random; they are not related to the...
Read more >
SPI EEPROM Interface Specification - Datakey
The instruction is neither accepted nor executed during a write ... nonvolatile cells that have the same properties and function as regular memory...
Read more >
Advanced data key configuration - ThingsBoard
However, there are times when it is not suitable to read the returning text to find out if a device is active or...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found