Odd behavior when the chart is initially rendered at certain widths #225
Send to my agentHere is another one for ya Tanner :P
When the chart is initially rendered at certain widths, it doesn't seem to be filling the parent container properly.
It initially has a bunch of extra space on the bottom and the xaxis overflows the right side of the container.
However when moving the dev tools panel over 1px the chart resizes and snaps to the position I would expect on initial render.
import React from 'react';
import { Chart } from 'react-charts';
export default function CustomChart() {
const primaryAxis = React.useMemo(
() => ({
isPrimary: true,
scaleType: 'time',
position: 'bottom',
getValue: (datum) => datum.primary,
}),
[]
);
const secondaryAxes = React.useMemo(
() => [
{
scaleType: 'linear',
position: 'left',
getValue: (datum) => datum.secondary,
elementType: 'line',
},
],
[]
);
return (
<div style={{ height: 300, border: '1px solid black' }}>
<Chart
options={{
data,
primaryAxis,
secondaryAxes,
}}
/>
</div>
);
}
const data = [
{
label: 'Series 1',
data: [
{
primary: new Date('2021-07-18T00:00:00.000Z'),
secondary: 100,
},
{
primary: new Date('2021-07-19T00:00:00.000Z'),
secondary: 36,
},
{
primary: new Date('2021-07-20T00:00:00.000Z'),
secondary: 20,
},
{
primary: new Date('2021-07-21T00:00:00.000Z'),
secondary: 30,
},
{
primary: new Date('2021-07-22T00:00:00.000Z'),
secondary: 92,
},
{
primary: new Date('2021-07-23T00:00:00.000Z'),
secondary: 85,
},
{
primary: new Date('2021-07-24T00:00:00.000Z'),
secondary: 45,
},
{
primary: new Date('2021-07-25T00:00:00.000Z'),
secondary: 60,
},
{
primary: new Date('2021-07-26T00:00:00.000Z'),
secondary: 16,
},
{
primary: new Date('2021-07-27T00:00:00.000Z'),
secondary: 16,
},
{
primary: new Date('2021-07-28T00:00:00.000Z'),
secondary: 16,
},
],
},
{
label: 'Series 2',
data: [
{
primary: new Date('2021-07-18T00:00:00.000Z'),
secondary: 10,
},
{
primary: new Date('2021-07-19T00:00:00.000Z'),
secondary: 85,
},
{
primary: new Date('2021-07-20T00:00:00.000Z'),
secondary: 90,
},
{
primary: new Date('2021-07-21T00:00:00.000Z'),
secondary: 15,
},
{
primary: new Date('2021-07-22T00:00:00.000Z'),
secondary: 60,
},
{
primary: new Date('2021-07-23T00:00:00.000Z'),
secondary: 18,
},
{
primary: new Date('2021-07-24T00:00:00.000Z'),
secondary: 63,
},
{
primary: new Date('2021-07-25T00:00:00.000Z'),
secondary: 87,
},
{
primary: new Date('2021-07-26T00:00:00.000Z'),
secondary: 23,
},
{
primary: new Date('2021-07-27T00:00:00.000Z'),
secondary: 83,
},
{
primary: new Date('2021-07-28T00:00:00.000Z'),
secondary: 83,
},
],
},
];beta.18
Can you get this to replicate exactly how it did here in a CodeSandBox?
That’ll help me debug it
You may have to adjust the browser view a few times to get a width that will show the issue
Got it replicated, thanks. I’ll get it fixed.
Fixed!
https://codesandbox.io/s/goofy-fast-sgs6i?file=/package.json
Fixed and upgraded a TON of stuff around dimensions and measuring. You also have a new
padding: number | { left?: number, right?: number, top?: number, bottom?: number}option for the chart too :)Enjoy!
Awesome. Nice Work!
MA-MacDonald(GitHub profile, opens in a new tab) closed this
Sign in to join this conversation.
Is this With the latest version?