1

I am using React Vis to create a simple Graph. This is my code:

import React from 'react';
import '../../../node_modules/react-vis/dist/style.css';
import {XYPlot, VerticalBarSeries} from 'react-vis';

const myData = [
  {x: 'A', y: 10},
  {x: 'B', y: 5},
  {x: 'C', y: 15}
]


export const Chart = () => {
  return (
      <XYPlot height={500} width={500}>
        <VerticalBarSeries data={myData} />
      </XYPlot>
  )
};

export default Chart;

I receive this error message: Received NaN for the `x` attribute. If this is expected, cast the value to a string."

When I change the x values in myData to ints, it works, but I need them as strings. The documentation clearly states that this should work: enter image description here

cachedcashew
  • 257
  • 2
  • 3
  • 9

1 Answers1

0

For the x value to be a string you need to add xType='ordinal' to the XYPlot as following:

export const Chart = () => {
  return (
      <XYPlot height={500} width={500} xType='ordinal'>
        <VerticalBarSeries data={myData} />
      </XYPlot>
  )
};

Now it should work for you.

K. Ali
  • 1
  • 1