Skip to content

Incorrect stacked bar rendering when final stack segment is missing #766

@gaardhus

Description

@gaardhus

I'm trying to render a stacked bar chart, but I'm running into some rendering problems when I have "missing" data.

I think the culprit is that the top of the stack is tied to the last entry, which makes the rendering weird when that is missing. I've adopted the example from the documentation and removed some entries to showcase the issue.

Image
<script lang="ts">
	import { BarChart } from 'layerchart';

	const wideData = [
		{
			year: 2019,
			apples: 3840,
			bananas: 1920,
			cherries: 960,
			grapes: 400
		},
		{
			year: 2018,
			apples: 1600,
			bananas: 1440,
			cherries: 960,
		},
		{
			year: 2017,
		},
		{
			year: 2016,
			apples: 820,
			bananas: 560,
			cherries: 720
		}
	];
</script>

<div class="h-[300px] rounded-sm border p-4">
	<BarChart
		data={wideData}
		x="year"
		series={[
			{ key: 'apples', color: 'var(--color-danger)' },
			{
				key: 'bananas',
				color: 'var(--color-warning)'
			},
			{
				key: 'cherries',
				color: 'var(--color-success)'
			},
			{
				key: 'grapes',
				color: 'var(--color-info)'
			}
		]}
		seriesLayout="stack"
		props={{
			xAxis: { format: 'none' },
			yAxis: { format: 'metric' },
			tooltip: {
				header: { format: 'none' }
			}
		}}
		legend
		renderContext="svg"
	/>
</div>

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions