Reputation: 3
So I'm trying to use the Google Sheets API for chart editing in R (using the googlesheets4 package's request_generate()
and request_make()
functions). I want to change the color of individual data labels in a bar chart (so the BasicChartSpec object), but not for an entire series.
Within the BasicChartSeries structure, you can add a DataLabel object and it accepts a TextFormat argument, but it looks like it only accepts one argument for all data labels in the series.
I saw the styleOverrides
argument that accepts a BasicSeriesDataPointStyleOverride object containing "index" (so you can specify which exact data point within the series) and "color" arguments. However, when I tried it, it changed the color for the bar / point itself, not the label.
I tried making these changes to a chart manually with the Google Sheets GUI (see image) and then using the gs4_get()
function (which uses the get API method) with fields = "sheets(charts)"
specified to see how R interpreted the chart through the Google Sheets API. What I saw is that the differing data label colors do show up in the styleOverrides
lists, but the only argument within it specified is the index. The R output for the "Category 1" series is below.
$basicChart$series
$basicChart$series[[1]]
$basicChart$series[[1]]$series
$basicChart$series[[1]]$series$sourceRange
$basicChart$series[[1]]$series$sourceRange$sources
$basicChart$series[[1]]$series$sourceRange$sources[[1]]
$basicChart$series[[1]]$series$sourceRange$sources[[1]]$sheetId
[1] 44021641
$basicChart$series[[1]]$series$sourceRange$sources[[1]]$startRowIndex
[1] 0
$basicChart$series[[1]]$series$sourceRange$sources[[1]]$endRowIndex
[1] 5
$basicChart$series[[1]]$series$sourceRange$sources[[1]]$startColumnIndex
[1] 2
$basicChart$series[[1]]$series$sourceRange$sources[[1]]$endColumnIndex
[1] 3
$basicChart$series[[1]]$targetAxis
[1] "LEFT_AXIS"
$basicChart$series[[1]]$dataLabel
$basicChart$series[[1]]$dataLabel$type
[1] "CUSTOM"
$basicChart$series[[1]]$dataLabel$textFormat
$basicChart$series[[1]]$dataLabel$textFormat$foregroundColor
named list()
$basicChart$series[[1]]$dataLabel$textFormat$fontFamily
[1] "sans-serif"
$basicChart$series[[1]]$dataLabel$textFormat$fontSize
[1] 12
$basicChart$series[[1]]$dataLabel$textFormat$foregroundColorStyle
$basicChart$series[[1]]$dataLabel$textFormat$foregroundColorStyle$rgbColor
named list()
$basicChart$series[[1]]$dataLabel$placement
[1] "OUTSIDE_END"
$basicChart$series[[1]]$dataLabel$customLabelData
$basicChart$series[[1]]$dataLabel$customLabelData$sourceRange
$basicChart$series[[1]]$dataLabel$customLabelData$sourceRange$sources
$basicChart$series[[1]]$dataLabel$customLabelData$sourceRange$sources[[1]]
$basicChart$series[[1]]$dataLabel$customLabelData$sourceRange$sources[[1]]$sheetId
[1] 44021641
$basicChart$series[[1]]$dataLabel$customLabelData$sourceRange$sources[[1]]$startRowIndex
[1] 0
$basicChart$series[[1]]$dataLabel$customLabelData$sourceRange$sources[[1]]$endRowIndex
[1] 5
$basicChart$series[[1]]$dataLabel$customLabelData$sourceRange$sources[[1]]$startColumnIndex
[1] 3
$basicChart$series[[1]]$dataLabel$customLabelData$sourceRange$sources[[1]]$endColumnIndex
[1] 4
$basicChart$series[[1]]$color
$basicChart$series[[1]]$color$green
[1] 0.3215686
$basicChart$series[[1]]$color$blue
[1] 1
**$basicChart$series[[1]]$styleOverrides
$basicChart$series[[1]]$styleOverrides[[1]]
named list()
$basicChart$series[[1]]$styleOverrides[[2]]
$basicChart$series[[1]]$styleOverrides[[2]]$index
[1] 1
$basicChart$series[[1]]$styleOverrides[[3]]
$basicChart$series[[1]]$styleOverrides[[3]]$index
[1] 2
$basicChart$series[[1]]$styleOverrides[[4]]
$basicChart$series[[1]]$styleOverrides[[4]]$index
[1] 3
**
$basicChart$series[[1]]$colorStyle
$basicChart$series[[1]]$colorStyle$rgbColor
$basicChart$series[[1]]$colorStyle$rgbColor$green
[1] 0.3215686
$basicChart$series[[1]]$colorStyle$rgbColor$blue
[1] 1
Does this mean that the Google Sheets API doesn't support this? Or is there something I'm missing? Has anyone else had success doing this with the Google Sheets API?
Upvotes: 0
Views: 70