Hi
What you need to do is step through the datatable, test the length of the
text in each cell, then change it if necessary.
Here's an example:
<script type="text/javascript">
var longText = (function() {
google.charts.load('current', {'packages':['table']});
google.charts.setOnLoadCallback(drawChart);
function drawChart() {
var queryString = encodeURIComponent('SELECT A,B,C ORDER BY A');
var query = new
google.visualization.Query('https://docs.google.com/spreadsheets/d/1tswaWUAbeBijHq4o505w0h7TmbD-qGhR3jBactcbGq0/gviz/tq?gid=1950745726&headers=1&tq='
+ queryString);
query.send(handleQueryResponse);
}
function handleQueryResponse(response) {
if (response.isError()) {
alert('Error in query: ' + response.getMessage() + ' ' +
response.getDetailedMessage());
return;
}
var quotes = response.getDataTable();
var totalRows = quotes.getNumberOfRows();
var totalCols = quotes.getNumberOfColumns();
var maxLength = 50;
for (i = 0; i < totalRows; i++) {
for (j = 1; j < totalCols; j++) {
var quote = quotes.getValue(i, j);
if (quote.length >= maxLength) {
quote = quote.slice(0,maxLength) + "...";
quotes.setValue(i,j,quote);
}
}
}
var chart = new
google.visualization.Table(document.getElementById('quotes_div'));
chart.draw(quotes);
}
})();
</script>
You can see this working at http://brisray.com/google-charts/getset.htm and
the original spreadsheet at
https://docs.google.com/spreadsheets/d/1tswaWUAbeBijHq4o505w0h7TmbD-qGhR3jBactcbGq0/#gid=1950745726
Instead of .slice you can use .substring
On Sunday, February 14, 2021 at 2:30:09 PM UTC-5 [email protected] wrote:
> Hi,
>
> I am using dataTable to show data return from sql query
> The columns are being created dynamaclly depend on the query
>
> for some column I can have long text inside column.
>
> I want to limit number of chars in columns to 50 chars for example and if
> there is longer text it will appear with elipsis
>
> I saw some example but none was working
> Can it be done and how ?
>
> Thanks
>
>
--
You received this message because you are subscribed to the Google Groups
"Google Visualization API" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/google-visualization-api/26c04364-29aa-4956-909f-68dc0cd2871fn%40googlegroups.com.