react-vis icon indicating copy to clipboard operation
react-vis copied to clipboard

Crosshair titleFormat

Open cvalmonte opened this issue 8 years ago • 4 comments

From the docs: titleFormat (optional) Type: function The function that formats the title for the crosshair. Receives the list of data points, should return an object containing title and value properties. Note: please pass custom contents in case if you need different look for the crosshair.

I pass an arrow function as a prop, which includes an object with title and value properties, like so:

<Crosshair
      values={crosshairValues}
      titleFormat={(d) => {{title: 'Date', value: new Date(d[0].x).toLocaleDateString()}}}
      itemsFormat={(d) => [{title: 'Queries made', value: d[0].y}, {title: 'Matches found', value: d[1].y}]}
/>

...and get this compilation error screen shot 2018-06-15 at 11 05 03 am

cvalmonte avatar Jun 15 '18 18:06 cvalmonte

Please understand that an Arrow function returns in-line object with this syntax

const getObj = () => ({ value: "hello world!" }); // instead of () => {{ ... }}

Your code should be:

<Crosshair
      values={crosshairValues}
      titleFormat={(d) => ({title: 'Date', value: new Date(d[0].x).toLocaleDateString()})}
      itemsFormat={(d) => [{title: 'Queries made', value: d[0].y}, {title: 'Matches found', value: d[1].y}]}
/>

😉 Btw, it's obvious that this is a Syntax error: Unexpected token, so I'd suggest finding a good IDE/Editor which will pop up warning/hint in such case.

lzhuor avatar Jun 18 '18 14:06 lzhuor

Doh! Thank you!

cvalmonte avatar Jun 18 '18 16:06 cvalmonte

How to pass title as blank, right now it's displaying : valuehere, how to get rid of : when title is null for titleFormat

utterly-calm avatar Nov 08 '18 08:11 utterly-calm

How to pass title as blank, right now it's displaying : valuehere, how to get rid of : when title is null for titleFormat

I have the same issue, did you find out solution?

ma-e avatar Jun 25 '19 20:06 ma-e