Stepped Stacked chart not seen as EmbeddedChart in Google sheets API? - charts

I am working with a spreadsheet that contains multiple sheets. In every sheet there is 1 chart.
I am using Google Apps Script to get these specific charts, which is working perfectly for all types of charts, except for the 'Stepped Stacked Chart', not to confuse with the 'Stepped Chart'.
Example code to explain the issue:
function getCharts(){
var ss = SpreadsheetApp.getActiveSpreadsheet();
var steppedStackedSheet = ss.getSheetByName('chart_2');
var otherChart = ss.getSheetByName('chart_1');
Logger.log(steppedStackedSheet.getCharts()); // returns an empty array
Logger.log(otherChart.getCharts()); // returns an array [EmbeddedChart] - This is what i also expect to see in the steppedStackedSheet chart.
}
I am buidling a script that downloads the chart as an image, but it's strange that this specific chart is not being recognized as a chart.
Haven't found anything on Google but hopefully someone here has had a similar issue and/or a solution.
Here an example sheet, also including the script
Thanks in advance!

As described in this documentation,
For 100% stacking, the stacks of elements at each domain-value are rescaled such that they add up to 100%. The options for this are isStacked: 'percent', which formats each value as a percentage of 100%, and isStacked: 'relative', which formats each value as a fraction of 1. There is also an isStacked: 'absolute' option, which is functionally equivalent to isStacked: true.
You may use setStacked() which uses stacked lines, meaning that line and bar values are stacked (accumulated). By default, there is no stacking. The return type is EmbeddedColumnChartBuilder.

Related

Cannot get correct type of chart: xlColumnStacked "variant 2" through vba code

I cannot assign the correct type of chart through VBA-code,
the type I need is "xlColumnStacked variant number 2"
Wanted variant
The code is run is the following:
ActiveSheet.ChartObjects("Chart 3").Activate
ActiveChart.ChartArea.Select
ActiveChart.ChartType = 52 'or synonymously : ActiveChart.ChartType = xlColumnStacked
This do not occur if the plot is already of the stacked format (still type 52 / xlColumnStacked), either in "bar og column"-stacked mode.
However, if I change the series which are displayed in the plot, the chart goes to "default" and I struggle to find any vba-code wise way to get back to the format which I want (see picture).
The thing is that I print these, for 80 series, and I hope to make that automated...
Received vba variant
I have had the same problem with changing line style on markers in scatter plot mode too, which made the same changes to the lines (between the markers) in the scatter plott.
The problem is that the name of the object is overlapping with another name it seems.
I (and also a helper from Microsoft) found a partial solution:
https://answers.microsoft.com/en-us/msoffice/forum/all/cannot-get-correct-type-of-chart-through-vba-code/ef57be1a-fab5-42a9-8d18-4af79e0cd5b2?messageId=9f8d32f2-d53d-449f-aa44-6d076ed5a1fe

How do you use ECharts' formatter to specify international number formats?

I'm building an API to create ECharts configs and would like the data labels to appear in the correct format based on where the end user is reading the chart from.
For example, if a number in a chart is 10,000 I would like it to appear as 10,000 in North America and 10.000 in Europe.
It looks like it's not possible to set a global format in ECharts, so I will need to use the formatter option. I thought this would be as simple as passing in a function that uses JavaScript's toLocaleString() or Intl.NumberFormat, but the ECharts docs make this look much more complicated.
I haven't found any examples of formatter that show both the inputs and outputs for common formatting scenarios, so I'm hoping to get some help in understanding the right way to do this.
Below is a very simple example of the function I'm hoping to include in formatter, but this particular example doesn't work.
formatter: function(d){
return d.toLocaleString()
}
Answering my own question so someone who needs this info can find it in the future. It turned out to be very simple, but I couldn't find a simple example like this anywhere!
Because ECharts was already displaying a value as a default label on my chart, I assumed that any function I included in formatter would use that value (that's the assumption in the simple function in my question).
I learned that when you add a function to formatter, it doesn't use the default value automatically. You need to pass in a specific reference to a piece of data using their params dataset.
In my example, I needed to use params.value to access the data I needed. My series dataset also includes both x and y columns in an array, so I needed to reference only one of the columns to get the labels to work.
params is detailed in the ECharts docs, but in the series type sections, it wasn't clear (at least to me) how to use it.
Here's what a simplified version of my working function looks like:
formatter: function(params){
let label = params.value[1] // this is my y column
return label.toLocaleString()
}

Adding and removing Measures dynamically in sapui5 VizFrame

I would like to change Measures dynamically in my VizFrame like in ChartDemo App from sapui5 docs [link below].
https://sapui5.netweaver.ondemand.com/test-resources/sap/viz/demokit/chartdemo/index.html
So when I click to one of my five checkboxes the proper Measure will be added or removed in case of unchecking.
I have one json from which I get data.
I've tried with this code:
if(oCheckBox.getSelected()){
oVizFrame.removeFeed(feedValuesAxis);
feedValuesAxis.setValues("ValueFromJSON");
oVizFrame.addFeed(feedValuesAxis);
}
But it causes error:
[50005] - valueAxis : does not meet the minimum or maximum number of
feeds definition.
I am using SAP UI5 version 1.28.
I have one VizFrame, one Dataset with all Measures and two FeedItem one for values and one for Dimension.
I guess I have to create a binding, right? But how should I do it? Thanks a lot for any pieces of advice.
Simply, I have missed array when putting value into setValues() method.
So the answer is:
feedValuesAxis.setValues(["ValueFromJSON"]);

Get all series from a chart with Google Apps Script

I have a sheet with 30 charts and I'm trying to iterate over all of them updating the colors of the background and the series.
Even though I could do it blindly, I'd rather be able to look at all the series in a chart first so that I could add extra logic based on the number of series, if it is already using one of my custom colors, title, etc. The problem is that I couldn't find a way to get the series from a chart.
Given that I can modify the series with setOptions I thought something like sheet.getCharts()[0].getOptions().get('series') would work, but it returns Access to class "(class)" is prohibited. when I try to log it.
Any advice on how to get an object where I can read information about the series in a chart?
its like hashmap (key/value) when you set option put key and value and when you get it try to use json to get the oject value too
function myfunction() {
var sheet = SpreadsheetApp.getActiveSheet();
var len = sheet.getCharts().length;
for(var i=0;i<len;i++){
var bg=sheet.getCharts()[i].getOptions().get('backgroundColor.fill');
var s=sheet.getCharts()[i].getOptions().get('series.0.color');
}
}

PNG area chart with Google Charts API?

I want to make an area chart with Google's Chart API, but it needs to be the PNG format one so I can build a PDF. Is that possible? The Chart Wizard does not seem to support area charts. Also, I want to do it in perl and the URI::GoogleChart module.
I spent a lot of time on this and discovered that I can do this:
See the example visually or the code below:
http://chart.apis.google.com/chart
?chxl=1:|week1|week2
&chxp=1,20,90
&chxr=0,0,120
&chxs=0,676767,11.5,0.5,l,676767|1,676767,9.5,0,_,676767
&chxt=y,x
&chs=300x278
&cht=lxy
&chco=FF9900,FF0000
&chds=6.667,100,0,110,0,100,0,118.333
&chd=t:-1|110,80|-1|43,32
&chdl=Total+Num|Special+Num
&chdlp=t
&chg=1,-1,1,0
&chls=2|2
&chma=8,0,0,7|54,2
&chtt=%23+Total+and+%23+Red+Items
&chts=000000,11.5
&chm=b,FF9900,0,1,0|B,FF0000,1,9,0
Where the last line b,color,startLine,endLine,0 means fill down to endLine and B,color,startLine,arbitraryNumber,0 means fill down to the bottom of the chart.
The solution came from Google's docs with some experimentation.