question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Responsive chart with width and height to 100%

See original GitHub issue

Hello

I am trying to implement a responsive pie chart with width and height to 100%.

The html code: <google-chart id="chart" [data]="pieChartData"></google-chart>

The relevant scss code:

#chart {
    position: absolute;
    top: 0;
    left: 50%;
    -webkit-transform: translate(-50%, 0);
    transform: translate(-50%, 0);
    width:100%;
    height:100%;
    @include rem(max-width, 350px); // just calculates the rem
    @include rem(max-height, 350px); // just calculates the rem
}

and the chartData object:

{
	chartType: "PieChart",
	dataTable: dataTable,
	options: {
		legend:"none",
		height: "100%",
		width: "100%",
	    chartArea: {
	        height: "94%",
	        width: "94%"
	    }
	}
}

For some reason setting “100%” in width and height does not work, hard coding those to e.g 350 will not make it responsive. Although the #chart in my browser ends up to 350 x 350 the enclosed div defaults to 350 x 200 I have tried using “100%” in plain javascript/css/html and it works. Any idea how to implement a responsive chart or what am am I doing wrong?

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Reactions:9
  • Comments:8

github_iconTop GitHub Comments

3reactions
gurachancommented, Feb 11, 2019

any updates? a version that uses angular flex is nice too

0reactions
thc2018commented, Dec 3, 2019
Read more comments on GitHub >

github_iconTop Results From Across the Web

Responsive Charts - Chart.js
When it comes to changing the chart size based on the window size, a major limitation is that the canvas render size (...
Read more >
Set height and width for responsive chart using recharts ...
The height / width will be 100% of the parent container in this case. Share.
Read more >
Using Responsive Features – amCharts 4 Documentation
amCharts 4 has a powerful responsive capabilities built into its core. ... E.g. for a chart that is 80px wide, both width <=...
Read more >
Chart Container - Concepts - Handbook - Apache ECharts
Listen to the Container Size to Change the Chart Size​​ For instance, the container has a height of 400px and a width of...
Read more >
Chart not following "Responsive Design" 100% Height
Chart not following "Responsive Design" 100% Height ... 100%; display: inline-block; zoom: 1; width: 99%; height: 34.65px; background-color: ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found