score:3
Accepted answer
in one chain, just for fun.
_.chain(data)
.groupby('status')
.mapobject(x => x.length)
.pairs()
.unzip()
.zip(['legend', 'data'])
.map(x => x.reverse())
.object()
.value();
score:0
just need one more step:
var output = {
legend: [],
data: []
}
_.chain(rawdata).groupby('status').each(function(value,key){
output.legend.push(key);
output.legend.push(data.length);
})
score:0
var legend = _.uniq(_.pluck(data, 'status'));
var groupeddata = _.groupby(data, 'status');
var result = {
legend: legend,
data: _.map(legend, function(status) {
return groupeddata[status].length;
})
};
Source: stackoverflow.com
Related Query
- UndescoreJS - Convert Object Properties Into Arrays
- How to Convert an Array of Objects into an Object of Associative Arrays in Javascript
- How to get hundreds of JS object properties into arrays to use as chart.js axes/data
- How to collect values of object properties into a list?
- Convert FirestoreCollection into an array?
- Convert two lists into a dictionary of X and Y Format
- Load data from a JSON object into an array
- React input to filter to chart. How convert a hardcoded number into a variable?
- How to convert JSON data to object that contains other objects?
- How to write better code in es6 for formatting an object with array values
- Convert SQLite PHP array into Javascript array?
- ChartJs Memory Leak | Garbage Collection does not clean Chart Object or Arrays after render
- Emberjs binding properties within Ember object
- is there a way in JavaScript/TypeScript of adding two arrays in an object and sort them?
- How to line break a label object in ChartsJS (nested arrays won't work)
- How to insert arrays into objects that are inside an array? For ng2-charts / Charts.js
- bind first property value of an array of object into chart.js
- How to push an array into an Object which is inside of another array?
- how to change object properties by on-click
- Chart.js - combine data and label into a single object
- Inserting data from arrays into a pie chart (chart.js)
- Dynamically create dataset objects for multi-line graphing, using pre-defined dataset object arrays (JavaScript / Chart.js)
- How to run Chart.js samples using source code
- Object list into chart labels not working
- How to wrangle JSON data into arrays of unknown name
- How to convert a bar chart into a triangle shaped chart using Chart JS?
- Split JSON into two arrays gives undefined keys-values
- Convert decimal values in array to percentages and pass all values into graph
- How to add labels into Chart.js canvas plugin?
- Get Chart js object from selector
More Query from same tag
- How to get certain text from json object value
- Loop to create lines for graph chartjs
- Doughnut chart updates with twice the data
- Dynamic rendering of chart with chartjs
- Function for Label in ChartJS?
- Problems displaying yLabels in charts.js
- Laravel PDF generation with Graph and send it with Email
- Failed to execute 'createLinearGradient' on 'CanvasRenderingContext2D': The provided double value is non-finite
- Not sure how to rerender chart in the app
- How to change line chart data label to icon or image in chart.js
- Chart.js - Responsiveness not correctly working on device orientation change
- each section of a pie chart to a random color in chartsjs
- How do I use plugins in ng2-charts?
- ChartJS: Custom tooltip always displaying
- function not return values
- Chart.js stacked bar chart text on top of the stacked bars
- Unable to change y-axis value dynamically based on data for Stacked bar chart in reactjs
- How to give break line in data label
- Reference external JS method in Chart.js callback using Chartjs.ror
- Could not find a declaration file for module chartjs-plugin-stacked100
- how to filter year from datefield in django
- Show "No data" in angular-chartjs line graph
- Displaying every nth label on the x-axis
- Chart.js line graph-removing labels on the line
- How to make the last item on the chart js active?
- Chart.js - cannot fetch result from MySQL via PHP
- Chart.js inside popup on leaflet?
- How do I resolve this error; 'document.getElementById('myChart').getContext' is undefined)?
- Angular 10 - Chart.js to draw chart in Array with convas id on runtime
- Chart.js line from annotations plugin is not appearing