Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Add padding or margin to a cell in Google chart table

I am using a Google chart in table mode and in the table I want the content (the text) having a little distance from the border. I try to do that with css but padding, margin and their variants with -left doesn't work so far. The css that is linked to the tableCell property (which is part of the cssClassNames property of the table of google chart) is working, cause I can set the border and back grounds. But when I try to set the padding or margin etc. nothing changes. So what do I need to do to create a distance between the border and the content in the table?

This is the Google chart table I am using: https://developers.google.com/chart/interactive/docs/gallery/table

like image 275
Cornelis Avatar asked Jul 05 '13 11:07

Cornelis


People also ask

How do I get rid of padding in Google chart?

To remove padding or margins from Google Charts and JavaScript, we can set the width and height options. const options = { title: "How Much I Ate Last Night", width: 350, height: 400, chartArea: { width: "100%", height: "80%" }, legend: { position: "bottom" }, }; to set the width and height in pixels.

How do you padding a table tag?

Cell padding is the space between cell borders and the content within a cell. To set cell padding in HTML, use the style attribute. The style attribute specifies an inline style for an element. The attribute is used with the HTML <table> tag, with the CSS property padding.

How do I add labels to a Google chart?

Double-click the chart you want to add notes to. At the right, click Setup. Add labels. Enter the data range with your notes.

How do you change the width of a bar in a Google chart?

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.


2 Answers

I hope this will help you. Add data to the rows using data.setCell as below

data.addColumn('string', 'Name');
            data.addColumn('number', 'Salary');
            data.addColumn('boolean', 'Full Time');
            data.addRows(5);
            data.setCell(0, 0, 'John',null,{'className':'right'});
            data.setCell(0, 1, 10000, '$10,000');
            data.setCell(0, 2, true);

Here is the working sample.

For more google chart related queries visit jqfaq.com

like image 198
Abinaya Selvaraju Avatar answered Nov 15 '22 08:11

Abinaya Selvaraju


I stumbled upon the same problem and couldn't find a quick answer (nor a clean one either).

The solution I used to fix (hack?) this is to have my CSS classes more specific than the one used by the API.

Before:

.my-row-class td {
    padding: 15px;
}

After

.my-row-class td, .google-visualization-table-table .my-row-class td {
    padding: 15px;
}

The selector that uses .google-visualization-table-table explicitly becomes more specific than the one used by Google in their API, hence it is applied last and overrides what Google has hardcoded in their API.

like image 23
Benoit Duffez Avatar answered Nov 15 '22 08:11

Benoit Duffez