You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
importEmberfrom'ember';/**Takes an array of data points like [1,2,5,4,5,5,2,1] andreturns the count ({1:2, 2:2, 4:1, 5:3}) of each item forGoogle Charts to consume.@method arrayToDataTable@param Array dataArray An array of items@param String [title] An optional column header@return Object The count of items in the array*/exportfunctionarrayToDataTable([dataArray=[],title]/*, hash*/){constcounter=dataArray.reduce((object,value)=>{if(!object[value]){object[value]=1;}else{object[value]++;}returnobject;},{});constdataTable=[[title,'Number of occurences']];for(letvalueincounter){constcount=counter[value];dataTable.addObject([value,count]);}returndataTable;}exportdefaultEmber.Helper.helper(arrayToDataTable);
The text was updated successfully, but these errors were encountered:
Apps now havewindow.google.visualization.arrayToDataTable(data) available and that seems like a better option than this helper.
If you haven't rendered a chart yet, you can load the necessary packages by calling loadPackages() in the GoogleCharts service.
This might be done like:
importComponentfrom'@ember/component';import{getOwner}from'@ember/application';exportdefaultComponent.extend({formatData: asyncfunction(){constservice=getOwner(this).lookup('service:google-charts');awaitservice.loadPackages();/* window.google.visualization should be available now */},});
The text was updated successfully, but these errors were encountered: