Piowar
August 15, 2024, 2:54pm
21
Thank you very much for your valuable advice and tips so far. The last graph you sent looks very good.
Although it still does not have a horizontal and vertical axis, the grid is OK. The only question is how you managed to get the vertical grid lines (dates are not numerical values).
TIMAI2
August 15, 2024, 3:05pm
22
It is only possible to set a vertical axis line in the spreadsheet chart configuration. problem is, this gets removed when you run a chart update !
You can set the colour of the horizontal gridlines but it seems only all of them...
By default there were some vertical gridlines, but i used this option:
.setOption('hAxis.gridlines.count',lr)
to set the number of gridlines to "more" than the number of records. lr
is the count of the total number of rows in the data.
Piowar
August 15, 2024, 4:10pm
23
Próbowałem, ale u mnie to nie działa
.setOption('hAxis.gridlines.count',lr)
Poniżej cały skrypt
function getData() {
var id_wykresu_kursu ='1pUDSCLb3TBYHqOqcEaLZQlKj2CPlCVdOL3A-aEDGagk';
var ile =15;
var ss = SpreadsheetApp.openById(id_wykresu_kursu);
SpreadsheetApp.setActiveSpreadsheet(ss);
var sheet = SpreadsheetApp.getActiveSheet();
var sh=ss.getSheetByName('Sheet1');
var lastRow_kursd =SpreadsheetApp.getActiveSheet().getLastRow();
var od_ktorego_rekordu =lastRow_kursd - ile +1;
var zakres ='';
zakres = 'A'+ od_ktorego_rekordu ;
zakres = zakres + ':C' + lastRow_kursd;
var lr = sh.getLastRow()+1;
var charts = sh.getCharts();
for (var i in charts) {
var chart = charts[i];
sh.removeChart(chart);
}
const range = sheet.getRange(zakres);
var dataRange = sheet.getDataRange();
var values = dataRange.getValues();
var chart = sh.newChart()
.setChartType(Charts.ChartType.LINE)
.setOption('backgroundColor','#dbffde')
.setOption('pointShape','square')
.setOption('pointSize',10)
.setOption('width',1000)
.setOption('height',300)
.setOption('title', 'Kurs euro')
.setOption('hAxis.title', 'Data')
.setOption('vAxis.title', 'Kurs euro')
.setOption('vAxis.minValue', 4.225)
.setOption('vAxis.maxValue', 4.325)
.setOption('hAxis.gridlines.count',lr)
.setOption('hAxis.slantedText',true)
.setOption('hAxis.slantedTextAngle',45)
.setOption('series',{1:{annotations: {textStyle: {fontSize: 12, color: 'black' }}}})
.setOption('series',{0:{dataLabel:'value'}})
.setOption('series',{1:{dataLabel:'value'}})
.setOption('series',{2:{dataLabel:'value'}})
.setOption('legend.position',null)
.setOption('vAxes', {})
.addRange(sh.getRange(zakres))
.setPosition(2, 4, 0, 0)
.build();
sh.insertChart(chart);
}
TIMAI2
August 15, 2024, 5:06pm
24
You have some doubling up in there...
Is the worksheet with your data on it called "Sheet1" ?
TIMAI2
August 15, 2024, 7:55pm
26
Well, I commented out most of the stuff that is not needed, and it generates a chart, based upon data in columns A and B:
function getData() {
//var id_wykresu_kursu ='1pUDSCLb3TBYHqOqcEaLZQlKj2CPlCVdOL3A-aEDGagk';
//var ile =15;
// var ss = SpreadsheetApp.openById(id_wykresu_kursu);
//SpreadsheetApp.setActiveSpreadsheet(ss);
//var sheet = SpreadsheetApp.getActiveSheet();
var ss = SpreadsheetApp.getActive();
var sh = ss.getSheetByName('Sheet1');
var lr = sh.getLastRow()+1;
//var sh=ss.getSheetByName('Sheet1');
//var lastRow_kursd =SpreadsheetApp.getActiveSheet().getLastRow();
//var od_ktorego_rekordu =lastRow_kursd - ile +1;
// var zakres ='';
// zakres = 'A'+ od_ktorego_rekordu ;
// zakres = zakres + ':C' + lastRow_kursd;
//var lr = sh.getLastRow()+1;
var charts = sh.getCharts();
for (var i in charts) {
var chart = charts[i];
sh.removeChart(chart);
}
//const range = sheet.getRange(zakres);
//var dataRange = sheet.getDataRange();
//var values = dataRange.getValues();
var chart = sh.newChart()
.setChartType(Charts.ChartType.LINE)
.setOption('backgroundColor','#dbffde')
.setOption('pointShape','square')
.setOption('pointSize',10)
.setOption('width',1000)
.setOption('height',300)
.setOption('title', 'Kurs euro')
.setOption('hAxis.title', 'Data')
.setOption('vAxis.title', 'Kurs euro')
.setOption('vAxis.minValue', 4.225)
.setOption('vAxis.maxValue', 4.325)
.setOption('hAxis.gridlines.count',lr)
.setOption('hAxis.slantedText',true)
.setOption('hAxis.slantedTextAngle',45)
//.setOption('series',{1:{annotations: {textStyle: {fontSize: 12, color: 'black' }}}})
.setOption('series',{0:{dataLabel:'value'}})
//.setOption('series',{1:{dataLabel:'value'}})
//.setOption('series',{2:{dataLabel:'value'}})
//.setOption('legend.position',null)
//.setOption('vAxes', {})
.addRange(sh.getRange("A2:B"+lr))
.setPosition(2, 4, 0, 0)
.build();
sh.insertChart(chart);
}
(Note: the google apps script is bound to the spreadsheet)
Piowar
August 16, 2024, 12:03pm
27
162 / 5 000
Wyniki tłumaczenia
Tłumaczenie
(Note: Google Apps Script is linked to the spreadsheet) I probably should know this but I don't know how to do it. Please give me instructions for dummies