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

Unable to display bar chart with one data point

Open JayFields opened this issue 8 years ago • 4 comments

VerticalBarSeries displays nothing when there is only a single item to plot. For example, data={[ { x: 1532647158000, y: 5 } ]}. Please see: https://codesandbox.io/s/509j7w48j4. I believe this was previously reported in #484 but it was closed. d3 handles a single data point by dividing the x-axis into thirds and plotting a single bar in the middle third, which seems reasonable to me.

JayFields avatar Jul 26 '18 20:07 JayFields

I made a quick workaround: https://codesandbox.io/s/9jjlk2jw4o in case it's useful as a starting point.

JayFields avatar Aug 08 '18 19:08 JayFields

I've tried to reproduce this issue and it only seems like it appears when xType is set to time? Is this the specific case you are trying to address? If you set xType="ordinal" i believe that youll get your desired functionality.

mcnuttandrew avatar Aug 20 '18 16:08 mcnuttandrew

Thanks, that works too. Yes, I'm working specifically with a time scale. But as you point out, with a vertical bar series I don't have to use a time scale.

JayFields avatar Aug 21 '18 18:08 JayFields

I would argue that even further, it maybe doesn't make sense to used a vertical bar series (and not a vertical rect series) as vertical distance is encoding time, but bar series uses it in a categorical way. Unless you have strenuous objection I'm going to close this.

mcnuttandrew avatar Aug 22 '18 04:08 mcnuttandrew