data-ui icon indicating copy to clipboard operation
data-ui copied to clipboard

LineSeries ordinal

Open royderksroute42 opened this issue 7 years ago • 3 comments

Hi there,

I've been trying for a (long) while but i can't figure out how to make an ordinal LineSeries - chart with String 'x' values. It seems to be unable to determine where its ticks should be; even when using numbers fo the 'x' value. Playing around with the numTicks properties and such all result in the same. Is this package capable of rendering a LineSeries?

data

[
        { x: 'car', y: 1 },
        { x: 'plane', y: 2 },
        { x: 'new york', y: 3 },
        { x: 'ocean', y: 4 },
        { x: 'pencil', y: 5 },
      ]
<XYChart
    height={height}
    width={width}
    xScale={{ type: 'ordinal' }}
    yScale={{ type: 'linear' }}
  >
    <LineSeries
      data={[
        { x: 'car', y: 1 },
        { x: 'plane', y: 2 },
        { x: 'new york', y: 3 },
        { x: 'ocean', y: 4 },
        { x: 'pencil', y: 5 },
      ]}
    />
    <XAxis />
    <YAxis />
  </XYChart>

screen shot 2018-10-30 at 14 17 19

royderksroute42 avatar Oct 30 '18 13:10 royderksroute42

Hey @royderksroute42 thanks for checking out @data-ui!

I think that you're right that something is up with the ordinal type scale, so I'll mark this as a bug to make sure that it gets resolved.

BUT you can work around this for now with a band scale and setting paddingInner = 1:

xScale={{ type: 'band', paddingInner: 1 }}

Here's a codesandbox to check out/play with, I hope that helps for the time being until I get a chance to fix it! (have been slammed at work recently but will try to get this fixed asap)

image

williaster avatar Oct 30 '18 18:10 williaster

Thank you for the quick reply, it seems the workaround is working as it should; the codesandbox was very useful and helped a lot. Cheers!

royderksroute42 avatar Nov 05 '18 15:11 royderksroute42

FYI this is due to ordinal type scales requiring full explicit domains for each value, which XYChart does not currently handle (it will set a 2-element min/max). Working on a fix to not require users to pass this in explicitly.

williaster avatar Nov 26 '18 19:11 williaster