Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

domain, chartBounds... how to set it correctly?? #349

Open
MatteoBrescianini opened this issue Sep 2, 2024 · 0 comments
Open

domain, chartBounds... how to set it correctly?? #349

MatteoBrescianini opened this issue Sep 2, 2024 · 0 comments

Comments

@MatteoBrescianini
Copy link

"I constantly have issues displaying the bars correctly in the group bar chart. I have a dynamic dataset, which can range from a few records to many, depending on the time interval selected by the user. It’s hard to find a usable combination of domain and padding... As the number of groups shown changes, the bars never start from the actual zero. I tried converting the 'from' and 'to' dates into milliseconds (UTC), but it doesn’t seem to react as expected... How can this issue be fixed?"

datasets shape: {
label: ' ',<--- date for each day (from the first requested to the last)
gridIn,
gridOut,
solar,
house,
}[];

my Code:

const font = useFont(commons);
const betweenGroupPadding = 0.1;
const withinGroupPadding = 0.1;
const roundedCorner = 5;

const startDate = new Date(data[0].label).getTime();
const endDate = new Date(data[data.length - 1].label).getTime();

return(
<View style={{ width: '100%', height: size, justifyContent: 'center' }}>
<CartesianChart
data={data}
xKey="label"
yKeys={['gridIn', 'gridOut', 'solar', 'house']}
domain={{
y: [
retrieveMinValue(data.map(el => [el.gridIn, el.gridOut, el.house, el.solar]).flat()),
retrieveMaxValue(data.map(el => [el.gridIn, el.gridOut, el.house, el.solar]).flat()),
],
x: [startDate, endDate],
}}
padding={{ right: 0, bottom: 5, top: 15 }}
domainPadding={{ left: 65, right: 50, top: 30 }}
axisOptions={{
formatYLabel: label => label + unit,
formatXLabel: label =>
label
? localeDateStringConvertion(label, undefined, {
day: '2-digit',
month: 'short',
}) ?? ''
: '',
font,
labelColor: '#d4d4d8',
}}>
{({ points, chartBounds }) => (
<BarGroup
chartBounds={chartBounds}
betweenGroupPadding={betweenGroupPadding}
// withinGroupPadding={withinGroupPadding}
roundedCorners={{
topLeft: roundedCorner,
topRight: roundedCorner,
}}>
<BarGroup.Bar points={points.gridIn} color={gridInColor} animate={{ type: 'timing' }} />
<BarGroup.Bar points={points.house} color={houseColor} animate={{ type: 'timing' }} />
<BarGroup.Bar points={points.gridOut} color={gridOutColor} animate={{ type: 'timing' }} />
<BarGroup.Bar points={points.solar} color={solarColor} animate={{ type: 'timing' }} />

)}


)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant