Google Spreadsheet Chart options returning same width for all charts - charts

Using apps script I want to increase the width and height of all the charts (any type of charts may be - generic) in a sheet. I tried the below code but it always alerts 371 x 600, no matter that charts are resized/shrink ed etc
var sheet = SpreadsheetApp.getActiveSheet();
var n = sheet.getCharts().length;
for (var i = 0; i < n; i++) {
var chart = sheet.getCharts()[i];
var th = chart.getOptions().get('height');
var tw = chart.getOptions().get('width');
showAlert(th + " " + tw);
chart = chart.modify()
.setOption('width', th + 20) //set increased width
.setOption('height', tw + 20) //set increased height
.build();
sheet.updateChart(chart);
}

It's working fine for me. (Note: the showAlert() function needs to be defined as described here: GAS-showAlert)
The only problem I see is that you've mixed up width and height variables for the Options in your code. But it is working for me, no problem.

Related

Alluvial plot - reorder lodes

I have created an alluvial plot but, for visibility purposes I would like to move one lode in one of the axes: more specifically I would like the "NA" of the "Type of surgery" to be at the top so the last 4 axes are aligned.
This is the code I used on R:
aes(y = ID, axis1 = Reason, axis2 = Response, axis3=Type_of_surgery, axis4=Margins, axis5=RT_post_op, axis6=Chemo_post_op)) +
geom_alluvium(aes(fill = Type_of_surgery), width = 1/12,aes.bind = TRUE) +
geom_flow(aes.bind = TRUE) +
geom_stratum(width = 1/3, fill = "grey", color = "white") +
geom_label(stat = "stratum", aes(label = after_stat(stratum))) +
scale_x_discrete(limits = c("Reason", "Response","Type of surgery", "Margins","RT post op", "Chemo post-op"), expand = c(0.1,0.1)) +
scale_fill_brewer(type = "qual", palette = "Pastel1") +
ggtitle("TBC") ```
This is the plot I obtained:
[Alluvial plot][1]
[1]: https://i.stack.imgur.com/nDCIZ.png
I am beginning on the world of coding so any help would be most welcome,
Thank you all for your help,
JB

How to get value at a point of line extended - TradingView Pine script

Im using the code below to draw a line:
//#version=4
simplesma = sma(close, 14)
var line3 = line.new(bar_index[0], high[0], bar_index, low, extend = extend.right)
line.set_xy1(line3, bar_index[5], simplesma[5])
line.set_xy2(line3, bar_index[3], simplesma[3])
That line has been drawn using 2 points in the history.
And then I use this code to draw a plot
price_point = line.get_price(line3,bar_index)
plot(price_point, title='Price', color=#ffcc00, transp=30)
Im trying to display the value on a label but the following code does not work:
var label3 = label.new(bar_index, high, text = "Value: "+ tostring(price_point, "#.########"), style = label.style_label_lower_left, color=#ffcc00, textcolor=#ff0000)
label.set_xy(label3,bar_index, price_point)
Can you please help me to show it on label ?
The variable price_point is the value at the current bar (bar_index). You don't need to use the function tostring().
Oh I found it.
var label3 = label.new(bar_index, high, text = "", style = label.style_label_lower_left, color=#ffcc00, textcolor=#ff0000)
label.set_xy(label3,bar_index, price_point)
label.set_text(label3, "Value: "+ tostring(price_point, "#.########"))

How do I maximize the window to multiple monitors in awesome wm?

I have three monitors in a horizontal line. Sometimes i want to maximize a window to three monitors at once, by pressing a combination of keys (and then returning it all back if necessary). How can I do that?
Untested, but the basic idea is to make the window floating and resize it to cover everything:
function(c)
c.floating = true
local geo = screen[1].geometry
geo.x2 = geo.x + geo.width
geo.y2 = geo.y + geo.height
for s in screen do
local geo2 = s.geometry
geo.x = math.min(geo.x, geo2.x)
geo.y = math.min(geo.y, geo2.y)
geo.x2 = math.max(geo.x2, geo2.x + geo2.width)
geo.y2 = math.max(geo.y2, geo2.y + geo2.height)
end
c:geometry{
x = geo.x,
y = geo.y,
width = geo.x2 - geo.x,
height = geo.y2 - geo.y
}
end
To undo the above, make the client no longer floating, i.e. c.floating = false.
Wiring the above to a keybinding is left as an exercise for the reader.

How do i stop clipping of limit line text in ios-charts?

I have a requirement for drawing the limit line which is near to the top of the chart and I want to keep limit line label on top right. Is there any way, it can not be truncated. Please see my output.
enter image description here
try limitline.labelPosition = ChartLimitLabelPositionRightBottom;
if you want keep labelPosition on top right,
you may can try set yourYAxis.spaceTop = x;
if x == 0, the maxValue will match the top of the chart,
if x == 1, the maxValue will match the centerY of the chart,
sorry, I can't express myself well, but, just try it.
hope it works.
The default renderer is little bit messed up. Subclass it (YAxisRenderer) and override method: renderLimitLines. Copy the content from original renderer and replace lines:
var clippingRect = viewPortHandler.contentRect
clippingRect.origin.y -= l.lineWidth / 2.0
clippingRect.size.height += l.lineWidth
with:
var clippingRect = viewPortHandler.contentRect
clippingRect.origin.y -= l.lineWidth / 2.0 + l.valueFont.lineHeight
clippingRect.size.height += l.lineWidth + l.valueFont.lineHeight
Now, as you have it prepared, you need to set your new axis renderer for
let yAxisRenderer = CenteredLimitLineYAxisRenderer(
viewPortHandler: chart.viewPortHandler,
yAxis: chart.leftAxis,
transformer: chart.getTransformer(forAxis: .left)
)
chart.leftYAxisRenderer = yAxisRenderer

read data from chart, ms as x value

i have some trouble with adding pinots to a chart and read them back to an array.
with tis code iam adding a new piont to my chart, y_value is a normal double var
time_stamp is a string with the current daytime (15:56:45:799) with millisecounds
string time_stamp = DateTime.Now.ToLongTimeString() + ":" + DateTime.Now.Millisecond.ToString();
chart_logger.Series[0].Points.AddXY(time_stamp, y_value);
after plotting the chart i want to save alle datapionts in an txt file, so i want the read all points form the chart
i tried it with
DataPoint[] asd = chart_logger.Series[0].Points.ToArray();
it read all the y values from the chart but i the x values are always zero
does someone have any idea
thanks for the help
Ralf
You need to use `ToOADate()' and 'FromOADate(double d)'.
chart_logger.Series[0].XValueType = ChartValueType.DateTime;
chart_logger.ChartAreas[0].AxisX.LabelStyle.Format = "MM/dd/yyyy HH:mm:ss.fff";
chart_logger.Series[0].Points.AddXY(DateTime.Now.ToOADate(), y_value);
DataPoint[] asd = chart_logger.Series[0].Points.ToArray();
var x = DateTime.FromOADate(asd[0].XValue);
Or
chart_logger.Series[0].YValuesPerPoint = 2;
var time = DateTime.Now;
string time_stamp = time.ToLongTimeString() + ":" + time.Now.Millisecond.ToString();
chart_logger.Series[0].Points.AddXY(time_stamp, y_value, time.ToOADate());
DataPoint[] asd = chart_logger.Series[0].Points.ToArray();
var x = DateTime.FromOADate(asd[0].YValues[1]);