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

[Question/Help] Resizing a pie chart #95

Open
BelugaWhale opened this issue Oct 19, 2023 · 1 comment
Open

[Question/Help] Resizing a pie chart #95

BelugaWhale opened this issue Oct 19, 2023 · 1 comment

Comments

@BelugaWhale
Copy link

BelugaWhale commented Oct 19, 2023

Hello, I am using code like this:

const chartData = { 
	type: 'pie', 
	width: 40,
	height: 40,
	data: { 
		labels: categories, 
		datasets: [{ 
			data: durations, 
			backgroundColor: backgroundColors, 
			borderColor: borderColors,
			borderWidth: 1
		}]
	}
};

window.renderChart(chartData, this.container);

The problem is just that it is too big! I have tried adjusting width and height as suggested in the documentation but no luck. https://charts.phibr0.de/Meta/Charts/Modifiers
Could anyone help me with this?

@kevsturman
Copy link

Had some success constraining the charts height by:

  1. Using responsive: true and maintainAspectRatio: false in the chart options.
  2. Rendering the chart in a div inside the container with a fixed height

eg.

const chartData = { 
    type: 'pie', 
    options: {
	    // options needed to keep chart sized inside container
		responsive: true, 
		maintainAspectRatio: false, 
        },
	width: 40,
	data: { 
		labels: categories, 
		datasets: [{ 
			data: durations, 
			backgroundColor: backgroundColors, 
			borderColor: borderColors,
			borderWidth: 1
		}]
	}
};

// Create a chart container div with a fixed height
dv.el("div", `<div class="chartView" style="height:150px"></div>`)
// render chart in chart container
window.renderChart(chartData, this.container.find(".chartView"))

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

2 participants