React-vis: Crosshair titleFormat

Created on 15 Jun 2018  路  4Comments  路  Source: uber/react-vis

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

Most helpful comment

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

All 4 comments

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.

Doh! Thank you!

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

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?

Was this page helpful?
0 / 5 - 0 ratings

Related issues

JayFields picture JayFields  路  5Comments

samhogg picture samhogg  路  4Comments

ZKruse picture ZKruse  路  4Comments

gespispace picture gespispace  路  3Comments

mcnuttandrew picture mcnuttandrew  路  5Comments