I am using Google Scripts to create a chart in Google Sheets however I have been having difficulties for a couple days now and I think it comes down to my lack of understanding of the syntax used by Google Scripts and its embedded chart object.
From my understand - and according to the syntax below:
To set the candlesticks rising colour to green I would do the following:
.setOption('candlestick', {risingColor: {fill: '#31d831'}})
However this doesn't work! I'd assume the syntax works like this:
candlestick.risingColor.fill
└────┬────┘ └────┬────┘ └──┴──────────────┐
└───────┐ └──────────┐ │
.setOption('candlestick', {risingColor: {fill: '#31d831'}})
I made this assumption because this code here works:
.setOption('vAxes', {0: {viewWindow: {min: 1}}})
The documentation is similar:
vAxis.viewWindow.min
└─┬─┘ └────────┬┘└─┴───────────────────┐
└──────────┐ └──────────┐ │
.setOption('vAxes', {0: {viewWindow: {min: 1}}})
|
┌────────────────────┴──────────────────────────────┐
This zero refers to the data set I would like to edit
Sidenote: While typing this I have also realised that I've spelt Axis
wrong as Axes
however this works Even through the documentation says Axis
I am thoroughly confused and I cannot find an answer anywhere my google-fu might of just been weak but I just cannot figure this out.
This is a similar question however they are not using embedded sheets and even when I copy their syntax it doesn't work!
Thank you in advance any help would be greatly appreciated!
Edit: Here is the code I am using to generate my chart:
const chart = data.newChart()
.setChartType(Charts.ChartType.CANDLESTICK)
.addRange(candle.getRange("a:e"))
.setOption('vAxes', {0: {viewWindow: {min: smallestValue-1, max: largestValue+1}}})
.setOption('candlestick', {risingColor: {stroke: '#31d831'}, fallingColor: {stroke: '#d83131', fill: '#ffffff'}}) // This is the line that doesn't work because I am unsure of the syntax!
.setOption('height', 735)
.setOption('width', 1175)
.setPosition(1, 1, 0, 0)
.build()
candle.insertChart(chart)
This syntax is different to the syntax in the second answer in the possible duplicate.
The accepted answer in that possible duplicate asks the user to export the chart and grab the options from there after creating it with the charts GUI in Google Sheets. However you cannot edit the colours in google sheets GUI for the Candlestick chart!
I know colouring is possible for the candlestick chart as the example in the documentation does it (This syntax here does not work when using .setOption() as explained in my original question)
I have also tried this syntax which is seen in this question:
var chart = data.newChart()
.setChartType(Charts.ChartType.CANDLESTICK)
.addRange(candle.getRange("a:e"))
.setOption('vAxes', {0: {viewWindow: {min: smallestValue-1, max: largestValue+1}}})
.setOption('candlestick.risingColor.stroke', '#31d831')
.setOption('candlestick.fallingColor.stroke', '#d83131')
.setOption('candlestick.fallingColor.fill', '#ffffff')
.setOption('height', 735)
.setOption('width', 1175)
.setPosition(1, 1, 0, 0)
.build()
candle.insertChart(chart)
However this doesn't work either
Final edit for anyone else: I have come to the conclusion that it is not possible to do what I am trying to do and with the help of TheMaster he has pointed me in the direction of using and taking advantage of the sidebar I have added this as an edit instead of the answer as maybe this might become possible one day and if it does It'd be nice to get this properly answered.
Good luck to anyone else looking into this in the future, keep me updated on its possibility!