I am able to create a table using the Google Docs Api. By default, each column is of equal width.
How is it possible to adjust the width of the columns using the Google Docs API?
I can see the updateTextStyle and updateParagraphStyle request types (batchUpdate methods) but there's currently no updateTable method, or any similar method that looks like it could do this. I'm using the reference documentation, here:
https://developers.google.com/docs/api/reference/rest/v1/documents/request
I'm using NodeJS / Javascript to interact with the API currently.
This is possible, in fact all the table operation that you can do on UI are possible.
1) Create table with following request:
def create_loc_table(doc_id, r, c, idx):
"""
r = number of rows,
c = number of columns,
idx = Start index where table needs to be created.
"""
request = [{
'insertTable': {
'rows': r,
'columns': c,
'location': {
'segmentId':'',
'index': idx
}
},
}
]
result = self.docs_service.documents().batchUpdate(documentId=doc_id, body={'requests': request}).execute()
print('Result {0}'.format(json.dumps(result, indent=4)))
2) Modify/update the table:
def modify_table(self, t_idx):
"""
t_idx = Table start index.
"""
request = [{
'updateTableColumnProperties': {
'tableStartLocation': {'index': t_idx},
'columnIndices': [0],
'tableColumnProperties': {
'widthType': 'FIXED_WIDTH',
'width': {
'magnitude': 100,
'unit': 'PT'
}
},
'fields': '*'
}
}
]
result = self.docs_service.documents().batchUpdate(documentId=doc_id, body={'requests': request}).execute()
print('Result {0}'.format(json.dumps(result, indent=4)))
3) Output would be
Related
Full example:
https://jsfiddle.net/gbeatty/4byg0p2t/
data: {
table: 'datatable',
startRow: 0,
endRow: 6,
startColumn: 0,
endColumn: 3,
parsed: function (columns) {
columns.forEach(column => {
column.splice(1, 2);
});
}
},
What I'd like the chart to reference is only column 0 "Year" and column 3 "Group C" while keeping the entire table displayed below. Challenge is disregarding the 2 columns in the middle.
I am trying the parsed option but it seems the rows and columns are mixed up. I even tried setting the switchRowsAndColumns value to true. (https://api.highcharts.com/highcharts/data.seriesMapping)
You can also use complete function to modify your data.
Example code based on your config:
complete: function(options) {
let series = [];
series.push(options.series[2]);
options.series = series;
}
Demo:
https://jsfiddle.net/BlackLabel/tfs4ubcL/
API Reference:
https://api.highcharts.com/highcharts/data.complete
I would like to create a Highcharts line graph with temperature data from multiple sensors each posting results at different times. The data is stored in a MySQL database as id, location, temp, timestamp. Since each sensor will be generating data at unique times the x values will not line up. For this reason I am interested in supplying each Highcharts series with a x- value and y-value... something like:
series: [{ // Location 1
name: 'Main Bedroom',
data: time1, temperature1
I am starting with a single location (MainBDRm) to develop my code.
I am using the following query to get and store multiple rows of data.
$sql = "SELECT temp, reading_time FROM ASHP_SensorData WHERE location = 'MainBDRm' ORDER BY reading_time DESC LIMIT 5";
while ($data = $result->fetch_assoc()){
$sensor_data[] = $data;
{
$temperature1 = json_encode(array_reverse(array_column($sensor_data, 'temp')), JSON_NUMERIC_CHECK);
$time1 = json_encode(array_reverse(array_column($sensor_data, 'reading_time')), JSON_NUMERIC_CHECK);
echo $temperature1 yields an array as [76,75,73,71,70]
echo $time1 yields an array as ["2021-12-19 17:07:13","2021-12-19 17:07:43","2021-12-19 17:08:13","2021-12-19 17:08:44","2021-12-19 17:09:14"]
I have confirmed that I can successfully produce a chart with
series: [{ // Location 1
name: 'Main Bedroom',
//yAxis: 0,
//showInLegend: true,
//data: temperature1, // works
data:[ // this works too
["2021-12-19 17:07:13", 76],
["2021-12-19 17:07:43", 75],
["2021-12-19 17:08:13", 73],
["2021-12-19 17:09:14", 71],
],
I would like to know if it is possible to use Json to preprocess the query results as a array in an array and use that as an input for the data: element with both the x & y values. Something like: ["2021-12-19 17:07:13", 76], ... , ["2021-12-19 17:09:14", 70]
I have tried
$stringToReturn = array();
$result = $conn->query($sql);
while ($data = $result->fetch_assoc()){
$sensor_data[] = $data;
array_push($stringToReturn, $data);
}
echo json_encode($stringToReturn, $data);
which yields:
[{"reading_time":"2021-12-19 22:24:33","temp":"79.70"},{"reading_time":"2021-12-19 22:24:03","temp":"79.70"},{"reading_time":"2021-12-19 22:23:33","temp":"79.70"},{"reading_time":"2021-12-19 22:23:03","temp":"79.70"},{"reading_time":"2021-12-19 22:22:33","temp":"79.70"}]
but I am not sure how to use this in the Highcharts script, or if it is in a usable form.
Notice that Highcharts expects to get x and y values in the data array, not custom names as "reading_time" or "temp", so you need to parse your data into the required format.
Demo: https://jsfiddle.net/BlackLabel/oe3j9fcp/
Or you can do it a few steps earlier: https://jsfiddle.net/BlackLabel/pd32q7zo/
API: https://api.highcharts.com/highcharts/series.line.data
When using google sheets api append method (in any language), the values to be appended to the sheet are added after the last non null row.
So new values appear at the bottom of the sheet, as explained here:
https://developers.google.com/sheets/api/reference/rest/v4/spreadsheets.values/append#InsertDataOption
How can I append values in a way that the new values appear at the top of the sheet?
You want to append values by inserting new rows. If my understanding is correct, how about this method? It seems that sheets.spreadsheets.values.append appends values to the last row. So I would like to propose to usesheets.spreadsheets.batchUpdate. The endpoint and request body are as follows. When you use this, please modify ### spreadsheet ID ###, "sheetId": 1234567890 and the parameters for range and values.
Endpoint :
POST https://sheets.googleapis.com/v4/spreadsheets/### spreadsheet ID ###:batchUpdate
Request body :
{
"requests": [
{
"insertRange": {
"range": {
"sheetId": 1234567890,
"startRowIndex": 0,
"endRowIndex": 1
},
"shiftDimension": "ROWS"
}
},
{
"pasteData": {
"data": "sample1, sample2, sample3",
"type": "PASTE_NORMAL",
"delimiter": ",",
"coordinate": {
"sheetId": 1234567890,
"rowIndex": 0,
}
}
}
]
}
Flow of this request :
Insert new row to row 1 using "insertRange".
Import values of "sample1, sample2, sample3" using "pasteData".
When the order of "insertRange" and "pasteData" is changed, at first, the value of "A1:A3" is overwritten. After this, the new row is inserted to the row 1. So it seems that the elements of "requests" which is an array run in the order.
Reference :
sheets.spreadsheets.batchUpdate
If I misunderstand your question, I'm sorry.
I'm using chartkick gem to render a Google timeline graph. While this works very nicely out of the box, I read on the Google documentation, that I'm also able to include a bar label:
https://developers.google.com/chart/interactive/docs/gallery/timeline#labeling-the-bars
Is there an option to add that extra column to the datatable with the help of Chartkick?
I basically need this to be invoked before the Timeline is rendered:
dataTable.addColumn({ type: 'string', id: 'Name' });
Thanks
Code sample:
<%= timeline [
["Washington", "1789-04-29", "1797-03-03"],
["Adams", "1797-03-03", "1801-03-03"],
["Jefferson", "1801-03-03", "1809-03-03"]
] %>
This requires a change in the source, chartkick.js:
First, you need to add a line describing the new data column to the beginning of "this.renderTimeline" (i've called it Label):
...
var data = new google.visualization.DataTable();
data.addColumn({type: "string", id: "Label"});
data.addColumn({type: "string", id: "Name"});
data.addColumn({type: "date", id: "Start"});
data.addColumn({type: "date", id: "End"});
data.addRows(chart.data);
Second, you need to update the "processTime" function, by adding 1 to the array values (since we've increased the array size by 1):
function processTime(chart)
{
var i, data = chart.rawData;
for (i = 0; i < data.length; i++) {
data[i][2] = toDate(data[i][2]); // from data[i][1]
data[i][3] = toDate(data[i][3]); // from data[i][2]
}
return data;
}
I'm experimenting with using Falcor to front the Guild Wars 2 API and want to use it to show game item details. I'm especially interested in building a router that can use multiple datasources to combine the results of different APIs.
The catch is, Item IDs in Guild Wars 2 aren't contiguous. Here's an example:
[
1,
2,
6,
11,
24,
56,
...
]
So I can't just write paths on the client like items[100..120].name because there's almost certainly going to be a bunch of holes in that list.
I've tried adding a route to my router so I can just request items, but that sends it into an infinite loop on the client. You can see that attempt on GitHub.
Any pointers on the correct way to structure this? As I think about it more maybe I want item.id instead?
You shouldn't find your self asking for ids from a Falcor JSON Graph object.
It seems like you want to build an array of game ids:
{
games: [
{ $type: "ref", value: ["gamesById", 352] },
{ $type: "ref", value: ["gamesById", 428] }
// ...
],
gamesById: {
352: {
gameProp1: ...,
},
428: {
gameProp2: ...
}
}
}
[games, {from: 5, to: 17 }, "gameProp1"]
Does that work?
You can use 'get' API of Falcor, It retrieves multiple values.. You can pass any number of required properties as shown below
var model=new falcor.Model({
cache:{
genereList:[
{name:"Recently Watched",
titles:[
{id:123,
name: "Ignatius",
rating: 4}
]
},
{name:"New Release",
titles:[
{id:124,
name: "Jessy",
rating: 3}
]
}
]
}
});
Getting single value
model.getValue('genereList[0].titles[0].name').
then(function(value){
console.log(value);
});
Getting multiple values
model.get('genereList[0..1].titles[0].name', 'genereList[0..1].titles[0].rating').
then(function(json){
console.log(JSON.stringify(json, null, 4));
})