Quantcast
Channel: Hot Weekly Questions - Web Applications Stack Exchange
Viewing all articles
Browse latest Browse all 9782

How to set V Axis formatting while updating charts via Google Script

$
0
0

I have a Google script to automatically adjust the 'Max' Value for the Vertical Axis based on the max value from a column in the source data. This part is working, but, the number format keeps changing to a date.

How it's outputting:

Incorrect Formatting

How I want it to output, after updating the V Axis:

How the V Axis should be formatted

My Script:

>     function updateChartMax() {>       // Reference the sheet containing the data>       var spreadsheet = SpreadsheetApp.getActiveSpreadsheet();>       var sourceSheet = spreadsheet.getSheetByName("Graph Data"); // Replace with your sheet name>       >       // Get the range of data from column O (15th column), starting from row 2>       var dataRange = sourceSheet.getRange(2, 15, sourceSheet.getLastRow() - 1); >       var columnData = dataRange.getValues(); >       var mat = Math.max(...columnData.flat()); // Find the maximum value in the column>     >       // Reference the sheet containing the chart>       var chartSheet = spreadsheet.getSheetByName("Manage"); // Replace with your chart sheet name>       var chart = chartSheet.getCharts()[0]; // Get the first chart on the sheet>     >       if (chart) { // Ensure the chart exists before modifying>         chart = chart.modify()>           .setOption('vAxes.0.viewWindow.max', mat) // Set the max value dynamically>           .setOption('vAxes.0.viewWindow.min', 0)  // Set the min value to 0>           .build();>         chartSheet.updateChart(chart); // Apply the changes to the chart>       } else {>         SpreadsheetApp.getUi().alert("No charts found on the sheet.");>       }>     }

I've tried changing the number format in the source data, using =to_pure_number and tried multiple different formatting options with no luck.


Viewing all articles
Browse latest Browse all 9782

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>