Created
May 18, 2016 15:43
-
-
Save zanza00/234a9078b5c58904df3086d11ea29457 to your computer and use it in GitHub Desktop.
how to convert the data from a Pie Chart to a Histogram in Highcharts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//Uses Highcharts and Rambda | |
// live example for conversion => http://goo.gl/I2OdwZ | |
// jsbin of result | |
var pieData = [ | |
{ y: 1.242, name: 'EM' }, { y: 29.017, name: 'EM' }, { y: 2.874, name: 'EM' }, { y: 0.474, name: 'EM' }, { y: 33.363, name: 'EM' }, { y: 33.03, name: 'EM' }, | |
{ y: 2.67, name: 'NA' }, { y: 28.551, name: 'NA' }, { y: 2.195, name: 'NA' }, { y: 0.524, name: 'NA' }, { y: 34.131, name: 'NA' }, { y: 31.929, name: 'NA' }, | |
{ y: 0.138, name: 'FE' }, { y: 28.115, name: 'FE' }, { y: 1.576, name: 'FE' }, { y: 0.829, name: 'FE' }, { y: 34.923, name: 'FE' }, { y: 34.419, name: 'FE' }, | |
{ y: 0.547, name: 'GC' }, { y: 25.642, name: 'GC' }, { y: 2.503, name: 'GC' }, { y: 0.398, name: 'GC' }, { y: 35.753, name: 'GC' }, { y: 35.157, name: 'GC' } | |
]; | |
var histogramData = R.uniq( pieData.map( function ( a ) { return a.name } ) ).map( function ( a ) { | |
return { | |
name: a, | |
series: R.filter( R.propEq( 'name', a ), pieData ).map( function ( a ) { return a.y; } ) | |
}; | |
} ); | |
//histogramData = [ | |
// {"name": "EM", "series": [1.242, 29.017, 2.874, 0.474, 33.363, 33.03]}, | |
// {"name": "NA", "series": [2.67, 28.551, 2.195, 0.524, 34.131, 31.929]}, | |
// {"name": "FE", "series": [0.138, 28.115, 1.576, 0.829, 34.923, 34.419]}, | |
// {"name": "GC", "series": [0.547, 25.642, 2.503, 0.398, 35.753, 35.157]} | |
//]; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment