Search code examples
google-sheetsgoogle-sheets-api

Get number format from source data for individual values in Google Sheets charts


In Google Sheets it is possible for data labels in a chart to reflect the number formats for individual scale points? Even if its only possible via the Google Sheets REST API that would be fine.

Currently it is possible in a chart to set the number format for data labels to "From source data", and data labels in the chart do successfully reflect that format.

But my problem is that the chart reads the custom number format only from the first cell in the source data, and then applies it to every data label in the series. Example

enter image description here

In the image below, the chart successfully reads the custom number format from the first value...

But what I want to get is like the mockedup image below:

enter image description here


Solution

  • You can work around the number format limitation with a helper column and some string manipulation. Enter the formula =text(C4,"0%") in D4 and copy it down the column for each value in column C. In D8 replace the formula with =char(9650)&" "&text(C8,"0%") and in D11 replace the formula with =char(9660)&" "&text(C11,"0%").

    Finally, in the chart options, change the source range to include column D, then under 'Series' click the three dots next to 'Qty', then on 'Add labels' and finally select the D4:D15 range.