You could try this:
// create rectangular shapes representing percentages of the (composite) histogram;
// 2017, use it at your own risk;
#target photoshop
if (app.documents.length > 0) {
var originalRulerUnits = app.preferences.rulerUnits;
app.preferences.rulerUnits = Units.PIXELS;
var myDocument = app.activeDocument;
var theName = myDocument.name;
try {var theName = theName.match(/(.*)\.[^\.]+$/)[1]} catch (e) {};
try {var thePath = myDocument.path}
catch (e) {var thePath = "~/Desktop"};
var theTotal = myDocument.width * myDocument.height;
// the values;
var theArray = new Array;
if (myDocument.mode == DocumentMode.MULTICHANNEL || myDocument.mode == DocumentMode.GRAYSCALE) {
var theHistogram = myDocument.channels[0].histogram
};
else {var theHistogram = myDocument.histogram};
// get total number of histogram:
var theNumber = 0;
for (var m = 0; m < theHistogram.length; m++) {
var thisValue = theHistogram;
theArray.push(thisValue);
theNumber = theNumber + theHistogram
};
if (theNumber != theTotal) {alert ("something’s wrong")}
else {};
// create shape layers;
var theX = myDocument.width;
var theWidth = myDocument.width;
var theBottom = myDocument.height;
var theTotal = theWidth * theBottom;
for (var n = 0; n < theArray.length; n++) {
// only if non-zero;
if (theArray != 0) {
var thePerc = theArray / theTotal;
rectangleShapeLayer ([0,0,theX,theBottom], n, n, n);
theX = theX - (thePerc * theWidth);
}
};
// reset;
app.preferences.rulerUnits = originalRulerUnits;
}
else {
alert ("no open document")
};
////// rectangle //////
function rectangleShapeLayer (theArray, theR, theG, theB) {
// =======================================================
var idMk = charIDToTypeID( "Mk " );
var desc44 = new ActionDescriptor();
var idnull = charIDToTypeID( "null" );
var ref9 = new ActionReference();
var idcontentLayer = stringIDToTypeID( "contentLayer" );
ref9.putClass( idcontentLayer );
desc44.putReference( idnull, ref9 );
var idUsng = charIDToTypeID( "Usng" );
var desc45 = new ActionDescriptor();
var idType = charIDToTypeID( "Type" );
var desc46 = new ActionDescriptor();
var idClr = charIDToTypeID( "Clr " );
var desc47 = new ActionDescriptor();
var idRd = charIDToTypeID( "Rd " );
desc47.putDouble( idRd, theR );
var idGrn = charIDToTypeID( "Grn " );
desc47.putDouble( idGrn, theG );
var idBl = charIDToTypeID( "Bl " );
desc47.putDouble( idBl, theB );
var idRGBC = charIDToTypeID( "RGBC" );
desc46.putObject( idClr, idRGBC, desc47 );
var idsolidColorLayer = stringIDToTypeID( "solidColorLayer" );
desc45.putObject( idType, idsolidColorLayer, desc46 );
var idShp = charIDToTypeID( "Shp " );
var desc48 = new ActionDescriptor();
var idunitValueQuadVersion = stringIDToTypeID( "unitValueQuadVersion" );
desc48.putInteger( idunitValueQuadVersion, 1 );
var idTop = charIDToTypeID( "Top " );
var idPxl = charIDToTypeID( "#Pxl" );
desc48.putUnitDouble( idTop, idPxl, theArray[1] );
var idLeft = charIDToTypeID( "Left" );
desc48.putUnitDouble( idLeft, idPxl, theArray[0] );
var idBtom = charIDToTypeID( "Btom" );
desc48.putUnitDouble( idBtom, idPxl, theArray[3] );
var idRght = charIDToTypeID( "Rght" );
desc48.putUnitDouble( idRght, idPxl, theArray[2] );
var idtopRight = stringIDToTypeID( "topRight" );
desc48.putUnitDouble( idtopRight, idPxl, 0.000000 );
var idtopLeft = stringIDToTypeID( "topLeft" );
desc48.putUnitDouble( idtopLeft, idPxl, 0.000000 );
var idbottomLeft = stringIDToTypeID( "bottomLeft" );
desc48.putUnitDouble( idbottomLeft, idPxl, 0.000000 );
var idbottomRight = stringIDToTypeID( "bottomRight" );
desc48.putUnitDouble( idbottomRight, idPxl, 0.000000 );
var idRctn = charIDToTypeID( "Rctn" );
desc45.putObject( idShp, idRctn, desc48 );
desc44.putObject( idUsng, idcontentLayer, desc45 );
var idLyrI = charIDToTypeID( "LyrI" );
desc44.putInteger( idLyrI, 5 );
executeAction( idMk, desc44, DialogModes.NO );
};