score:19
countBy could be used instead of groupBy:
var techArray = [
{ project: 'Project1', tech: 'Java'},
{ project: 'Project2', tech: 'Excel'},
{ project: 'Project3', tech: 'SAS'},
{ project: 'Project4', tech: 'Java'},
];
var counts = _.countBy(techArray,'tech');
This will return an object with the tech as properties and their value as the count:
{ Java: 2, Excel: 1, SAS: 1 }
To get the data in the form for highcharts use map instead of each:
var data = _.map(counts, function(value, key){
return {
name: key,
y: value
};
});
score:0
This should work
var techArray = [['Project1','Java'], ['Project2', 'excel'], ['Project3', 'Java']];
var chartData = [];
var techData = _.groupBy(techArray, function(item) {
return item[1];
});
_.each(techData, function(value, key) {
var techCount = value.length;
chartData.push({
name: key,
y: techCount
});
});
_.groupBy
needs to either get a property name, or a function that returns the value being grouped. There is no tech
property of an array, so you cant group by it. But, as our techArray
is an array of tuples, we can pass a function _.groupBy
that returns the value that we want to groupBy, namely the second item in each tuple.
chartData
now looks like this:
[{
name: 'Java',
y: 2
}, {
name: 'excel',
y: 1
}]
Source: stackoverflow.com
Related Query
- Grouping / counting in javascript using underscore.js
- How do I dynamically change a data point in Highcharts using JavaScript
- Javascript Highcharts v3.0.5 - How to hide Y Axis Title when using multiple Y Axis
- JavaScript error when using Highcharts
- Optimize JavaScript DrillDown code
- Convert hours and minute to millisecond using javascript or jQuery
- Using PhantomJS to create HighCharts grahps server side for use in PDF creation (PHP) - results in exit code 11 from PHPs exec();
- Query rails database, and update highcharts using Javascript
- JavaScript code inside TypeScript file .ts not working
- How to set values in JavaScript (Highcharts) using PHP
- when printing page with highcharts using javascript this.print() width values in css in @media print seem to be ignored
- c# WPF Webbrowser with Highchart, Javascript from external source not working "An error has occurred in the script on this page"
- Display HTML table inside a DIV using Javascript switch statement
- passing formatting JavaScript code to HighCharts with JSON
- Embed javascript code in a django template
- How to hide an element using javascript
- Highcharts display label for pie chart using html table as data source
- Javascript not working when using async attribute : Highcharts
- Update data of existing Highstock graph using only JavaScript
- HTML Content to Javascript Code
- change marginLeft and marginRight from a javascript statment using highcharts
- Using HTML5 Custom Data Attributes to pass data from <div to javascript
- Strange character in the Highstock source code
- HTML table as data source for highstock charts using highcharts
- tool that shows javascript errors in code
- Repeating Javascript Code
- Heatmap multiple data labels for the same axis in dynamic way using javascript
- Conditional Highcharts Marker Symbol Using Javascript
- how to add custom class name to tick positioner in Highcharts using javascript
- How to create a drilleable bar graph in jsp page using open source charts API
More Query from same tag
- How do I pass an array for more than one series of random x-y data to Highcharts?
- How to use html/unicode symbols as marker-symbols in highcharts?
- Adding call outs to a Highcharts - Stacked Bar
- BootStrap collapse incorrect sizes
- get values of date-input-boxes from rangeSelector
- Angular cannot using Highcharts X-range series
- adding element with array_push() with looping to create json data
- Can I use highcharts in a pdf generate with prawn in Rails?
- How to use no-data-to-display within Highcharts-Vue wrapper
- Ability to show labels of checked serie after rendering highcharts
- Highcharts shared tooltip(for line series) - Change on hover ACCORDING TO PLOTBAND
- How to change Highchart tooltip font family
- Highcharts tooltip for single series always centre. Can I force it to be left hover of the marker?
- Highcharts series graph to start and end on tick and end on max
- In HighCharts, I Can't display data returned from ajax call
- Highchart - Datalabel overlaps across slices
- Change Highchart Options dynamically in angular
- Highcharts - how to put bubble chart in straight line?
- How to plot incomplete series with highchart
- Highcharts time X axis
- Add spacing between points in HighChart
- How change time frame in hc_xAxis - month in quartal
- highcharts custom colors and tootip point color
- highcharts redraw() with function that references newly redrawn chart
- how do I pass the Ajax response data in my highcharts
- How to set an option in Highchart inactive by default
- Chart position in highchart
- The right order of values for Bollinger Bands
- Can highcharts drilldown of a chart, reflect on another chart?
- highcharts polar chart with gradient color fills