Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to make bar chart not be crushed with a lot of data in google bar chart?

Using a bar chart: https://developers.google.com/chart/interactive/docs/gallery/barchart when you have a lot of data, it crushes the bars to be very thin and the text to overlap each other. What options are there to get the data to render in the container properly (maybe guarantee each bar to be of a certain height if possible)? I want to avoid explicitly setting the height to say "1000px", then looking at the bar chart to determine whether it is scrunched up or not.

like image 267
Rolando Avatar asked Aug 22 '13 18:08

Rolando


People also ask

How do I customize my Google bar graph?

Customize a bar chartChoose an option: Chart style: Change how the chart looks. Chart & axis titles: Edit or format title text. Series: Change bar colors, axis location, or add error bars, data labels, or trendline.

How do you space a bar graph in Google Sheets?

Here are the steps. Right-click on any column inside your chart. Select 'Format data series'. Drag the slider under the 'Gap width' to the right to make the columns thinner and to the left to make the columns wider.


1 Answers

You can calculate a height for your BarChart dynamically, based on the number of rows of data in your DataTable:

// set inner height to 30 pixels per row
var chartAreaHeight = data.getNumberOfRows() * 30;
// add padding to outer height to accomodate title, axis labels, etc
var chartHeight = chartAreaHeight + 80;
var chart = new google.visualization.BarChart(document.querySelector('#chart_div'));
chart.draw(data, {
    height: chartHeight,
    chartArea: {
        height: chartAreaHeight
    }
});
like image 102
asgallant Avatar answered Oct 08 '22 04:10

asgallant